[pthread] thread self & equal
2009-12-29 19:15:17| 分类:
pthread
| 标签:
|举报
|字号大中小 订阅
Too simple to explain, just read the code.
----------------------------------
#include <stdio.h>
#include <pthread.h>
pthread_t pid;
void *mythr1(void *_)
{
printf("#1 equal = %d\n", pthread_equal(pid, pthread_self()));
return (void *)0;
}
void *mythr2(void *_)
{
printf("#2 equal = %d\n", pthread_equal(pid, pthread_self()));
return (void *)0;
}
int main()
{
pthread_t pid2;
pthread_create(&pid, NULL, mythr1, NULL);
pthread_create(&pid2, NULL, mythr2, NULL);
pthread_join(pid, NULL);
pthread_join(pid2, NULL);
return 0;
}
----------------------------------
$ ./a.out
#1 equal = 1
#2 equal = 0
----------------------------------
评论这张
转发至微博
转发至微博
评论