Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between pthread_exit() and exit()?

Tags:

c

pthreads

What's the difference between pthread_exit() and exit()?

like image 851
The unknown Avatar asked Jun 22 '12 15:06

The unknown


People also ask

What is the use of pthread_exit () function?

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.

What is the difference between pthread_exit and pthread_join?

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.

What does exit () do in a thread?

Thread#exit() : exit() is a Thread class method which is used to terminates the thread and schedules another thread to be run.

What is the use of pthread_join () and pthread_exit () function?

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.


3 Answers

Did you read man pages?

exit() performs normal program termination, while pthread_exit() kills calling thread.

like image 90
arrowd Avatar answered Oct 16 '22 22:10

arrowd


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.

like image 20
Dancrumb Avatar answered Oct 17 '22 00:10

Dancrumb


the differences:

pthread_exit(): terminate a thread-whether its work is done or not exit() perfoms normal program termination for the entire process.

like image 40
user3842385 Avatar answered Oct 17 '22 00:10

user3842385