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).