nikos
nikos

Reputation: 393

pthread_exit from a function called from a thread

Suppose i create a thread that ,in some point, calls a function foo(). If i call pthread_exit() from within foo, will that have as a result termination of the thread that called foo?

thanks, Nikos

Upvotes: 1

Views: 208

Answers (4)

Martin James
Martin James

Reputation: 24907

Sure - thread context is unaffected by call/return. The thread IS calling pthread_exit(), no matter how long the call stack is. If 20 threads call foo then all 20 threads will exit.

Rgds, Martin

Upvotes: 0

George Kastrinis
George Kastrinis

Reputation: 5182

Of course. Otherwise what's the point of pthread_exit in the first place. http://www.kernel.org/doc/man-pages/online/pages/man3/pthread_exit.3.html "The pthread_exit() function shall terminate the calling thread"

Upvotes: 2

user405725
user405725

Reputation:

Yes, of course. It will also result in calling cleanup code, if any. Beware that it won't automatically clean application resources like mutexes etc. See pthread_exit() documentation for more information.

Upvotes: 0

user2100815
user2100815

Reputation:

From the documentation:

The pthread_exit() function terminates the calling thread

Upvotes: 0

Related Questions