Terminating Threads

Syntax

When the function that is created as a thread executes its last statement, the corresponding thread terminates. After the termination of a thread, the memory and its execution become unavailable. In many cases, we many want to terminate a thread at other places and in this case function thr_exit() should be used:

#include  <thread.h>

size_t    status;

void  thr_exit(void *status);
where setting the parameter to NULL works the best. The thread executing thr_exit() terminates.

Do not use exit() to terminate a thread or the main program. Otherwise, the whole program, including all threads the main program has, terminates.