pthread_join usage
What happens if i call pthread_join(NULL) 开发者_如何学C?
you get a compile time error; pthread_join()
expects 2 arguments :)
If the first of the two expected arguments to pthread_join() is NULL, anything (bad) can happen at runtime. From the specification at www.opengroup.org: "The behavior is undefined if the value specified by the thread argument to pthread_join() does not refer to a joinable thread."
NULL is accepted for the second argument of pthread_join().
EDIT: Indeed some implementations can specify the behavior. Check man page for pthread_join on your system.
Ideally you would always check the function return:
if (0 != pthread_join(thread, &result))
{
fprintf(stderr, "pthread_join error\n");
}
If successful, the pthread_join() function returns zero. Otherwise, an error number is returned to indicate the error.
精彩评论