Without looking at the rest of the code, I can only venture a guess. My intuition says, the called thread procedure (the user-supplied start_routine
parameter) should never return to the calling function.
Think about it: if the new thread did return, you would have two threads running over the same original code path. I imagine that the thread function that is actually called is a wrapper that calls the user-supplied start_routine
. When the start_routine
returns, the wrapper then calls pthread_exit
.
(main thread)
v
pthread_create
v
thread_setup (sets up stack), and spawns new thread
v |
return to main thread |
|
|
v
wrapper_function
v
user-supplied start_routine
| (returns)
v
wrapper_function calls
v
pthread_exit
Again, this is just a guess, but the whole point is, the new thread should never return to the code that called pthread_create
. The purpose of the wrapper then would be to ensure that pthread_exit
gets called.
I would have to see what they are passing as routine
to thread_setup
.
My feelings are confirmed by the fact that you don't have to call pthread_exit
.