Thread: Probably very easy question about pthread mutexes

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jun 2009
    Posts
    101
    Quote Originally Posted by synthetix View Post
    I only need a filename variable from the producer thread, so I tried unlocking each thread after they acquire the filename. This works well, but once the loop in the producer is complete, the program quits before waiting for the rest of the threads to complete. This happens because those threads freed their locks very early, after they got their filenames. The real number crunching takes a little time so of course the producer thread quits immediately, terminating the worker threads while they're in the middle of crunching.
    To deal with this, should I call pthread_join() for as many worker threads exist?

    Here:

    Code:
    for(i=0;i<num_threads;i++){
    	pthread_join(threads[i],NULL);
    }
    
    return 0; //end of main
    Actually, I just tried this, and it doesn't work since each thread is running an endless while() loop. Should I add a condition to the while()?
    Last edited by synthetix; 11-03-2011 at 07:05 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. question about the pthread.
    By thungmail in forum C Programming
    Replies: 4
    Last Post: 10-31-2009, 09:38 PM
  2. Pthread question
    By gundamz2001 in forum C Programming
    Replies: 3
    Last Post: 09-16-2009, 04:04 AM
  3. pthread question
    By quantt in forum Linux Programming
    Replies: 7
    Last Post: 04-07-2009, 01:21 AM
  4. Mutexes and Blocking
    By NuNn in forum C Programming
    Replies: 2
    Last Post: 03-12-2009, 03:32 PM
  5. Easy question, (should be) easy answer... ;-)
    By Unregistered in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 06-12-2002, 09:36 PM