In linux, the whole process exits when the main thread terminates no matter how it terminates,by the function exit() or returns from main. If the main thread returns from main(),it will return to the “C runtime” known as crt.o or something like that. In the crt.o,whose c code like this: exit(main(argc, argv)); exit() will be called by the main thread
eventually, as a result, all the threads terminate.
Does my thought seem right?
If in the crt.o exit() is replaced by a thread terminating function like void thread_exit(int),which can only terminates a thread with an exit status, the c source code of crt.o seems like thread_exit(main(argc,argv)),do other thread still run when the main thread terminates?
Returning from
mainis equivalent to callingexit, and terminates the process. To terminate just a single thread, usepthread_exit. Note that it’s valid for the initial thread to callpthread_exit(and the process does not terminate until all threads have exited or until one of them callsexit) and threads other than the initial thread implicitly callpthread_exitif you return from their start functions.