首页 新闻 会员 周边

先pthread_cancel()再pthread_join()

0
[已关闭问题] 关闭于 2011-10-19 20:10

程序如下:

#include<pthread.h>
#include<iostream>
#include<unistd.h>

using namespace std;

void *thread(void *arg)
{
cout << "in thread, tid = " << pthread_self() << endl;

sleep(60);

return (void *)12;
}

int main()
{
pthread_t tid;
if(pthread_create(&tid, NULL, thread, 0) != 0)
{
cout << "pthread_create error" << endl;
return 0;
}

pthread_cancel(tid);

int *r;
pthread_join(tid, (void**)&r);

cout << PTHREAD_CANCELED << endl;
cout << r << endl;

cout << "in main thread, tid = " << pthread_self() << endl;
return 0;
}

为什么在“pthread_join(tid, (void**)&r);”之后主线程就退出了?不输出下面3个cout?

r是不是“PTHREAD_CANCELED“?

lq0729的主页 lq0729 | 初学一级 | 园豆:200
提问于:2011-10-19 09:51
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册