I\'m writing a Unix application in C which uses multiple threads of control. I\'m having a problem with the main function terminating before the thread it has spawned have a
Yes one of doing this is to use pthread_join
function: that's assuming your thread is in "joinable" state.
pthread_create
: after this function returns control, your thread will be executing your thread function.
after pthread_create
, use the tid from pthread_create to pthread__join
.
If your thread is detached, you must use some other technique e.g. shared variable, waiting on signal(s), shared queue etc.
Great reference material available here.