Subj : Re: Thread management To : comp.programming.threads From : loic-dev Date : Tue Oct 11 2005 06:54 am Hello guyom, > I have a problem with thread synchronization. > In a TCP server on incoming request, I create a thread to manage the > request. > I want that the function, in whih I create the thread, terminates > before the thread. Generally it's OK but sometimes the created thread > finishes before that the main function return. [snip] > And the problem comes from the thread synchronization. Some times the > created thread as the time to start and finished before the main > function calls the MyTrace function and exit. > > Does someone know how to force teh main function to finish before the > thread ? Use a condition variable to tell your thread from your "main" function, that it should now run. Just before returning from the function, signal the thread using pthread_cond_signal() or pthread_cond_broadcast(). The first thing that your thread should do is to wait on the condition variable using pthread_cond_wait(). The predicate associated to the condition variable could be something like thread_runable, which becomes true when the "main" function is about to return. HTH, Lo=EFc. N=2EB: Is guyom is short-hand for guillaume? .