If many threads are to be created by not waiting for existing threads to terminate (i.e., not calling pthread_join), we need some way of cleaning up after threads when they do terminate.
For multiple child processes this is usually done in a signal handler since a parent process receives a signal when a child terminates.
An different method is used for threads. Assuming we don't need to do anything when a created thread terminates, we can arrange that the thread implementation simply cleans up the thread resources completely when the thread terminates.
To do this, it is only necessary to call:
pthead_detach(thread); // thread is the integer id for the thread
This call can either be done in the caller just after creation, or in the thread's own start function.