O'Reilly logo

Hands-On System Programming with Linux by Kaiwan N Billimoria

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

So many ways to die

How can a thread terminate? It turns out there are several ways:

  • Explicitly, by invoking pthread_exit(3).
  • Implicitly, by returning from the thread function; the return value is implicitly passed (as though via pthread_exit parameter). 
  • Implicitly, by falling off the thread function; that is, hitting the close brace }; note however that this is not recommended (a later discussion will show you why)
  • Any thread invoking the exit(3) API will, of course, cause the entire process, along with all threads in it, to die.
  • The thread gets canceled (which we will cover later).

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required