Return from main will cause exit to be called.
Calling exit implicitly or explicitly terminates the process and all its threads.
If a thread whose initial function is not main returns or calls pthread_exit(n) will terminate just that thread.
This can result in zombie threads if no thread in the process has yet pthread_join.
Note that thread id's in general may be reused. It is considered unsafe to call pthread_join more than once with the same thread id. This may or may not be detected.