- 论坛徽章:
- 0
|
在我的机器上不是这样的结果,而是下面的结果,唉,太郁闷了
#include <stdio.h>
#include <pthread.h>
pthread_key_t key;
void echomsg(void* t)
{
printf("destructor excuted in thread %08x,param=%08x\n",(unsigned int)pthread_self(),(unsigned int)t);
}
void * child1(void *arg)
{
pthread_t tid = pthread_self();
printf("thread %08x enter\n",(unsigned int)tid);
pthread_setspecific(key,(void *)&tid);
printf("thread %08x returns %08x\n",tid,pthread_getspecific(key));
}
int main(void)
{
pthread_t tid = pthread_self();
printf("mainthread %08x enter\n",(unsigned int)tid);
pthread_t tid1;
printf("hello\n");
pthread_key_create(&key,echomsg);
pthread_create(&tid1,NULL,child1,NULL);
//sleep(10);//.....echomsg(int t).....
pthread_join(tid1,NULL);//....echomsg(int t).....
pthread_key_delete(key);
printf("main thread exit\n");
return 0;
}
mainthread 40041280 enter
hello
thread 40841cc0 enter
thread 40841cc0 returns 408418b0
destructor excuted in thread 40041280,param=408418b0
main thread exit |
|