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?
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.
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.