简体   繁体   中英

pthread_join usage

如果我调用pthread_join(NULL)会发生什么?

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.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM