The default state of creating a thread is joinable. If a thread stops running but is not joined, its state is similar to zombie process in the process, that is, some resources are not recycled (exit status code). Therefore, the thread Creator should call pthread_join to wait until the thread stops running and obtain the exit code of the thread, reclaim resources (similar to wait and waitpid)
However, after pthread_join (pthread_id) is called, if the thread does not end, the caller will be blocked. In some cases, we do not want this to happen, for example, when the main thread creates a subthread for each new link in the web server for processing, the main thread does not want to block it because it calls pthread_join (because it still needs to process the incoming link). In this case, you can add the code pthread_detach (pthread_self () in the Child thread ())
Or the parent thread calls
Pthread_detach (thread_id) (non-blocking, can be returned immediately)
This sets the sub-thread status to detached, and all resources are automatically released after the thread finishes running.