今日OS作业:
gettid()和pthread_self()的区别
查阅了很多资料做了一个小总结(来源于别的文章):
- gettid()是linux内核实现的函数,在内核看来任何线程也是一个轻量级进程,从下面内核实现的sys_gettid看来,gettid()返回的是内核管理的轻量级进程的进程id。
- pthread_self 得到实际上是线程描述符pthread 指针地址。
- gettid()是内核给线程(轻量级进程)分配的进程id,全局(所有进程中)唯一;pthread_self()是在用户态实现的,获取的id实际上是主线程分配给子线程的线程描述符的地址而已,只是在当前进程空间中是唯一的。