c++ thread id

 

#include <stdio.h>
#include <pthread.h>
#include <sys/syscall.h>

void *func(void *argv) {
    pthread_t thread = pthread_self();
    printf("%0lx\n", thread);

    long p_id = syscall(SYS_gettid);
    printf("%lu\n", p_id);
}

int main() {
    pthread_t thread;
    pthread_create(&thread, NULL, func, NULL);
    printf("main() thread: %0lx\n", thread);

    pthread_join(thread, NULL);

    return 0;
}

mutian@mutian:~/soft/compile$ gcc t.c -lpthread
mutian@mutian:~/soft/compile$ ./a.out
main() thread: 7f81f9817700
7f81f9817700
11849

posted @ 2015-12-31 13:09  牧 天  阅读(634)  评论(0)    收藏  举报