Thread termination with pthread_exit followed by return - Strange example

165 views Asked by At

I found this example; here the two threads threadDefault and threadCustomized are terminated by using pthread_exit followed by return. Why did the author write both instructions?

2

There are 2 answers

2
R.. GitHub STOP HELPING ICE On BEST ANSWER

Mohith Reddy's answer is correct but misses the point. Of course the return statement is never executed since pthread_exit doesn't return, but it's there to suppress warnings from the compiler in case it's not aware that pthread_exit doesn't return.

2
m0hithreddy On

From the pthread_exit() man page:

RETURN VALUE

This function does not return to the caller.

ERRORS

This function always succeeds.

NOTES

Performing a return from the start function of any thread other than the main thread results in an implicit call to pthread_exit(), using the function's return value as the thread's exit status.

The above all suggests that pthread_exit(); and return NULL; are redundant when both are called together.