pthread_join的使用注意事项

1. 函数声明

int pthread_join(pthread_t thread, void **retval);

2.函数说明

  -阻塞并一致等待线程结束;

  -线程需要是PTHREAD_CREATE_JOINABLE属性的;

  -不关心返回值,调用pthread_join(tid, NULL);

  -关心返回值,调用ret = NULL; pthread_join(tid, ret);

   注意线程内调用pthread_exit(retval ),retval不能指向临时变量,一般使用堆空间、常量区上的变量;

3.返回值

  -成功返回0;

  -失败返回-1;如果线程被取消,也返回-1;

posted @ 2022-06-24 11:56  猿起5-2  阅读(167)  评论(0)    收藏  举报