MemoryGarden's Blog

努力 -----------大能猫

C++博客 首页 新随笔 联系 聚合 管理
  118 Posts :: 11 Stories :: 20 Comments :: 0 Trackbacks
pthread_t pthread_self();  获取线程自身ID

int pthread_equal(pthread_t threadid1, pthread_t thread2)  判断两个线程ID是否相等,返回0 不相等,非零相等。


 1 #include <pthread.h>
 2 #include <stdio.h>
 3 int main(){
 4 
 5   pthread_t pid1;
 6   pthread_t pid2;
 7 
 8   pid1 = pthread_self();
 9   pid2 = pthread_self();
10 
11   printf("pid1:%u, pid2:%u, equal:%d", (unsigned int)pid1, (unsigned int)pid2, (pthread_equal(pid1, pid2) > 0));
12 
13 
14 
15   return 0;
16 }
17 

g++ ./pthread_self.cpp -lpthread -o pthread_self

输出:
pid1:545519376, pid2:545519376, equal:1





posted on 2011-06-06 14:46 memorygarden 阅读(1537) 评论(0)  编辑 收藏 引用 所属分类: 网络编程

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理