title: Why asctime(localtime(&ltime)) function does work on gcc 4.8.4 properly and cause problem with gcc 9.4.0
body: <pre><code>ltime=time(NULL);
  sprintf(buffer,&quot;\n%sTwo matrices of size %dx%d have been read. The number of threads is %d \n&quot;,asctime(localtime(&amp;ltime)),side_Array,side_Array,val_M);
  write(STDOUT_FILENO,buffer,strlen(buffer));
  </code></pre>
  <p>This the code that cause problem with output file that threads write into it. I know that localtime is not thread safe function however, i used localtime in gcc 4.8.4 it workes properly. I am sure that localtime is the problem but i don't get it why it doesn't cause problem with gcc 4.8.4 and is there any possible solution with changing makefile?</p>
  <p>Here is my main:</p>
  <pre><code>int main(int argc, char *argv[])
  {
      ltime=time(NULL);
      sprintf(buffer,&quot;\n%sTwo matrices of size %dx%d have been read. The number of threads is %d \n&quot;,asctime(localtime(&amp;ltime)),side_Array,side_Array,val_M);
      write(STDOUT_FILENO,buffer,strlen(buffer));
  
  // reading file, creating arrays
  
      pthread_mutex_init (&amp;mutex, NULL);
  
  
      threadsArr = malloc(sizeof(pthread_t) * val_M);
  
      for(i = 0; i &lt; val_M; ++i){
          prm_i = malloc(sizeof(*prm_i));
          *prm_i = i;
           pthread_create(&amp;(threadsArr[i]), NULL, threads, prm_i);
      }
  
  
      for(i = 0; i &lt; val_M; ++i){
          pthread_join(threadsArr[i],NULL);
      }
  
      //Threads write result into arr_DFT and because of localtime this calculation gives wrong result.
  
      for(i = 0; i &lt; side_Array; i++)
      {
         for(j = 0; j &lt; side_Array; j++)
         {
             sprintf(buffer, &quot;%.3f + (%.3fi),&quot;,arr_DFT[i][j].real, arr_DFT[i][j].imag);
             write(fd_csv, buffer, strlen(buffer));
         }
         write(fd_csv, newLine, strlen(newLine));
      }
  
  
  }
  </code></pre>
  <p>Here is my thread:</p>
  <pre><code>void *threads(void *arg1){
      //mathematical calculations
  
      pthread_mutex_lock(&amp;mutex);
      ++arrived;
      end = clock();
      time_spend = (double)(end - begin) / CLOCKS_PER_SEC;
      sprintf(printBuffer,&quot;%sThread %d has arrived the rendezvous point in %.2f seconds.\n&quot;,asctime(localtime(&amp;ltime)),tempVal+1, time_spend);
      write(STDOUT_FILENO, printBuffer, strlen(printBuffer));
  
  
      if(arrived &lt; val_M)
          pthread_cond_wait(&amp;conditionVar, &amp;mutex);
  
      else
          pthread_cond_broadcast(&amp;conditionVar);
  
      pthread_mutex_unlock(&amp;mutex);
      sprintf(printBuffer,&quot;%sThread %d is advancing the second part.\n&quot;,asctime(localtime(&amp;ltime)), tempVal+1);
      write(STDOUT_FILENO, printBuffer, strlen(printBuffer));
      begin = clock();
  
      // mathematical calculations
  
      end = clock();
      time_spend = (double)(end - begin) / CLOCKS_PER_SEC;
      sprintf(printBuffer, &quot;%sThread %d has finished the second part in %f seconds \n&quot;,asctime(localtime(&amp;ltime)),tempVal+1, time_spend);
      write(STDOUT_FILENO, printBuffer, strlen(printBuffer));
      return NULL;
  }
  
  
  </code></pre>
  <p>Here is my makefile:</p>
  <pre><code>all: 
      gcc -Wall main.c -o hw5 -pthread -lm
  
  clean:
      rm -f *o &amp;&amp; rm -f hw5
  </code></pre>