pthread_exit

当主线程调用pthread_exit时,其余线程不退出,继续执行

当主线程调用exit/或return时,其余线程退出,整个进程都退出了。

 #include <pthread.h>
#include <stdio.h>
#include<stdlib.h>
#include <unistd.h> #include <pthread.h> void* new_thread(void* arg)
{
while()
{
printf("new thread\n");
fflush(stdout);
sleep();
}
return NULL;
} int main(void)
{
pthread_t tid; int err = pthread_create(&tid, NULL, new_thread, (void *));
sleep();
printf("call pthread_exit\n");
fflush(stdout);
//pthread_exit(NULL); return ;
}

当mian中条用pthread_exit 时,new_thread 继续运行。

当main中直接return时,new_thread 停止运行,进程退出了。

上一篇:Zookeeper会话


下一篇:[兼容]IE下textarea滚动条不能滚动