比较几个退出函数
pthread_exit():退出当前线程
exit():退出当前进程
return:返回到调用者那里去
一、pthread_exit函数:将单个线程退出
void pthread_exit(void *retval);
参数retval表示线程退出状态,通常传NULL
在线程中,禁止使用exit函数,因为会导致进程内所有线程全部退出,因此在多线程环境中,应尽量少用exit
函数,取而代之用pthread_exit
函数,将单个线程退出
另外需注意,pthread_exit或return返回的指针所指向的内存单元必须是全局的或者是用malloc分配的,不能在线程函数的栈上分配,因为当其他线程得到这个返回指针时线程函数已经退出了
二、pthread_join函数
阻塞等待线程退出,获取线程退出状态,其作用对应进程中waitpid()函数
三、 pthread_cancle函数:终止线程
四、pthread_detach
线程属性设置分离线程⭐
👇
======》