程序如下:
#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“?