获取线程ID
来源:互联网 发布:大数据时代电子商务 编辑:程序博客网 时间:2024/05/16 10:58
pthread_t结构体:
typedef struct {
void * p; /* Pointer to actual object */
unsigned int x; /* Extra information - reuse count etc */
} ptw32_handle_t;
typedef ptw32_handle_t pthread_t;
创建线程:
int pthread_create(pthread_t *tidp,const pthread_attr_t *attr,
(void*)(start_rtn)(void),void *arg);
获取进程ID:getpid();
获取线程自身ID:pthread_self();
函数参数
第一个参数为指向线程标识符的指针。
第二个参数用来设置线程属性。
第三个参数是线程运行函数的起始地址。
最后一个参数是运行函数的参数。
eg:
void printids(const char *s)
{
pid_t pid;
pthread_t tid;
pid = getpid();
tid = pthread_self();
printf(“%s pid %u tid %u (0x%x)\n”, s, (unsigned int) pid,
(unsigned int) tid, (unsigned int) tid);
}
void *thr_fn(void *arg)
{
printids(“new thread: “);
return NULL;
}
int main(void)
{
int err;
pthread_t ntid;
err = pthread_create(&ntid, NULL, thr_fn, NULL);
if (err != 0)
printf(“can’t create thread: %s\n”, strerror(err));
printids(“main thread:”);
pthread_join(ntid,NULL);
return EXIT_SUCCESS;
}`
- Linux获取线程ID
- 获取线程ID
- 获取线程ID
- 获取线程ID
- Liunx获取线程Id
- 3.4 线程id获取
- linux获取线程ID
- linux下获取线程id
- linux 下获取线程ID
- linux多线程,获取线程ID
- 获取当前进程ID和子线程的线程ID
- gettid()获取线程ID测试程序
- linux 获取线程ID的方法
- 获取进程和线程id函数简介
- linux 获取线程ID的方法
- 获取当前线程的id号 gettid()
- 根据线程ID获取其Handle
- 获取线程id的另一种方法
- Android组件——使用DrawerLayout仿网易新闻v4.4侧滑菜单
- JavaScript学习笔记之BOM
- 批处理连接网络打印机
- ssh_互信 简洁实例__代码
- linux下so动态库一些不为人知的秘密
- 获取线程ID
- 运行时异常
- 开源项目分类汇总
- C#制表符过滤处理方法
- 【软考】【非对称加密与认证】
- Itself is Itself(scu1617)
- Xcode 6制作动态及静态Framework以及问题的解决
- XMPP聊天软件客户端开发(3)
- 解决Github访问超慢的问题