Is it OK to call pthread_exit from main?

Well its definately legal in the linux implementation of pthreads, see the notes section in pthreads_exit. It states

To allow other threads to continue execution, the main thread should terminate
by calling pthread_exit() rather than exit(3).

Further, a look at the source code here (torwads the end) shows that it roughly translates to _endthread or _endthreadex. The documentation here for those makes no mention of not calling it in the initial thread.

Leave a Comment