title: reading file line by line using pthreads ... exits unexpectedly
body: <p>I have the following code:</p>
  
  <pre><code>    /*//not important
      FILE * INFILE;
      list_file = optarg;
      if( ( INFILE = fopen( list_file, "a+" ) ) == NULL ) {
          fprintf( stderr, "Can't open input file\n");
          exit(0);
      }
      */
  
      pthread_mutex_t input_queue;
      pthread_mutex_init(&amp;input_queue, NULL);
  
      for( i = 0 ; i &lt; number_thread; i++)
      {
          if( pthread_create( &amp;thread_id[i], NULL, &amp;work, NULL) != 0 )
          {
              i--;
              fprintf(stderr, RED "\nError in creating thread\n" NONE);
          }
      }
      for( i = 0 ; i &lt; number_thread; i++)
          if( pthread_join( thread_id[i], NULL) != 0 )
          {
              fprintf(stderr, RED "\nError in joining thread\n" NONE);
          }
  
  
  
  
      void * work(void * data)
      {
          unsigned long line;
          char buf[512];
          while ( !feof(INFILE) )
          {
              pthread_mutex_lock(&amp;input_queue);
              fgets((char *)&amp;buf, sizeof(buf), INFILE);
              if (buf[strlen (buf) - 1] == '\n')
                  buf[strlen (buf) - 1] = '\0';
              line = (unsigned long)buf;
              pthread_mutex_unlock(&amp;input_queue);
              do_work( line );
          }
          fclose(INFILE);
          return NULL;
      }
  </code></pre>
  
  <p>it reads lines from file but after a while it exits unexpectedly, no error message.
  I guess I messed up something.</p>
  
  <p><em><strong>How can I read the file line by line using pthreads but keep as much as possible the code unchanged (I mean not to mess up the whole program) ?</em></strong></p>