So, usually it is a good idea to wait until the spawned threads complete their life before terminating. To do that, in term of POSIX API, we use the pthread_join() function.Referring to the previous post, where we created the new thread like this:
pthread_t thread;We can now wait that the other thread completes its run calling:
pthread_create(&thread, /* ... */);
pthread_join(thread, NULL);The second parameter, when not NULL, would refer to the memory location where the value returned by the function on which that thread runs should be stored.
This function too returns zero if the specified thread joins happily, otherwise a non-zero value showing something bad happened.