For some reason I thought that calling pthread_exit(NULL)
at the end of a main function would guarantee that all running threads (at least created in the main funct
pthread_join
does the following :
The
pthread_join()
function suspends execution of the calling thread until the target thread terminates, unless the target thread has already terminated. On return from a successfulpthread_join()
call with a non-NULLvalue_ptr
argument, the value passed topthread_exit()
by the terminating thread is made available in the location referenced byvalue_ptr
. When apthread_join()
returns successfully, the target thread has been terminated. The results of multiple simultaneous calls topthread_join()
specifying the same target thread are undefined. If the thread callingpthread_join()
is canceled, then the target thread will not be detached.
However you can achieve the same by using a light weight loop which will prevent the exe
from exiting. In Glib this is achieved by creating a GMainLoop, in Gtk+ you can use the gtk_main.
After completion of threads you have to quit the main loop or call gtk_exit
.
Alternatively you can create you own wait functionality using a combination of sockets,pipes and select system call but this is not required and can be considered as an exercise for practice.