免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1626 | 回复: 0
打印 上一主题 下一主题

gettid 和pthread_self的区别 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-11-30 09:08 |只看该作者 |倒序浏览
gettid 和pthread_self的区别
The man page for gettid says:
The thread ID returned by this call is not the same thing as a POSIX thread ID
(i.e., the opaque value returned by pthread_self(3)).
看来,线程的id,在linux中分为POSIX thread ID , 和内核中对每一个线程的id.
gettid是linux 的一个系统调用, 查看sys_gettid
/* Thread ID - the internal kernel "pid" */
asmlinkage long sys_gettid(void)
{
    return task_pid_vnr(current);
}
struct upid {
    /* Try to keep pid_chain in the same cacheline as nr for find_pid */
    int nr;
    struct pid_namespace *ns;
    struct hlist_node pid_chain;
};
struct pid
{
    atomic_t count;
    /* lists of tasks that use this pid */
    struct hlist_head tasks[PIDTYPE_MAX];
    struct rcu_head rcu;
    int level;
    struct upid numbers[1];
};
这里面的level不清楚是什么含义? 有知道的告诉我,多谢了。
问:_syscall[0-6]跑哪里去了
答:没有了
问:那现在用啥呢?
答:用系统调用 syscall(2),第一个参数是SYS_name,后面参数照写
#define _GNU_SOURCE
#include stdio.h>
#include sys/types.h>
#include pthread.h>
#include stdlib.h>
#include string.h>
#include unistd.h>
#include linux/unistd.h>
#include sys/syscall.h>
void *thsf(void *arg)
{
    pthread_t th;
    char *retstr;
    retstr=malloc(50);
    memset(retstr,0,50);
    strcpy(retstr,"New thread quit!");
    th=pthread_self();
#if 1
    printf("New thread,pid:%d,tid:%x,another tid:%x.\n",
                      getpid(),
                      th,
                      (long)syscall(SYS_gettid));
#endif
   
    pthread_exit(retstr);
}
int main()
{
        pthread_t nth1,mth,oth;
        void *a;
        if(<span style="color: rgb(255, 0, 0);"%

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/24474/showart_1672518.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP