What's the difference between pthread_exit()
and exit()
?
The pthread_exit() function terminates the calling thread, making its exit status available to any waiting threads. Normally, a thread terminates by returning from the start routine that was specified in the pthread_create() call which started it.
pthread_exit is called from the thread itself to terminate its execution (and return a result) early. pthread_join is called from another thread (usually the thread that created it) to wait for a thread to terminate and obtain its return value.
Thread#exit() : exit() is a Thread class method which is used to terminates the thread and schedules another thread to be run.
On return from a successful pthread_join() call with a non-NULL value_ptr argument, the value passed to pthread_exit() by the terminating thread shall be made available in the location referenced by value_ptr. When a pthread_join() returns successfully, the target thread has been terminated.
Did you read man pages?
exit()
performs normal program termination, while pthread_exit()
kills calling thread.
pthread_exit
terminates a thread. Per the docs
Thread termination does not release any application visible process resources, including, but not limited to, mutexes and file descriptors, nor does it perform any process level cleanup actions, including, but not limited to, calling any atexit() routines that may exist.
exit
, on the other hand, does do this.
the differences:
pthread_exit(): terminate a thread-whether its work is done or not exit() perfoms normal program termination for the entire process.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With