4f1 Subj : Thread management To : comp.programming.threads From : guyom Date : Tue Oct 11 2005 04:16 am Hello, 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. Here is a part of my code : The pThreadDetach attribute is initialized as follow pthread_attr_init(&pThreadDetach); pthread_attr_setdetachstate(&pThreadDetach,PTHREAD_CREATE_DETACHED); The function which receives the incoming request and create the thread is as follow : IncomingReq-function(); { iThreadOK = pthread_create(&TabUser[localId].ThreadHandle,&pThreadDetach,THREAD_WnpIMAP_GetAttach,(void *)localId); if (iThreadOK) { MyTrace("Create Thread has failed\n"); return -1; } MyTrace("Create Thread OK\n"); return 0; } 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 ? . 0