当前位置: 首页 > news >正文

建设部网站官网考试桂林北站是高铁站吗

建设部网站官网考试,桂林北站是高铁站吗,东莞做网站怎么样,盐城网站制作网络推广这里讲的是通过 pthread_create() 函数返回的线程 id,其实就是 glibc 库里维护的线程id,它跟内核维护的线程 id 不一样,pthread_create() 返回的线程 id 并不一定是唯一的。我们看 pthread_create 函数的源码,它最后返回的线程 id…

        这里讲的是通过 pthread_create() 函数返回的线程 id,其实就是 glibc 库里维护的线程id,它跟内核维护的线程 id 不一样,pthread_create() 返回的线程 id 并不一定是唯一的。我们看 pthread_create 函数的源码,它最后返回的线程 id 是什么样的?

      //.............................../* Check for valid priorities.  */int minprio = INTERNAL_SYSCALL (sched_get_priority_min, scerr, 1,iattr->schedpolicy);int maxprio = INTERNAL_SYSCALL (sched_get_priority_max, scerr, 1,iattr->schedpolicy);if (pd->schedparam.sched_priority < minprio|| pd->schedparam.sched_priority > maxprio){/* Perhaps a thread wants to change the IDs and if waitingfor this stillborn thread.  */if (__builtin_expect (atomic_exchange_acq (&pd->setxid_futex, 0)== -2, 0))lll_futex_wake (&pd->setxid_futex, 1, LLL_PRIVATE);__deallocate_stack (pd);return EINVAL;}}/* Pass the descriptor to the caller.  */*newthread = (pthread_t) pd;LIBC_PROBE (pthread_create, 4, newthread, attr, start_routine, arg);/* Start the thread.  */return create_thread (pd, iattr, STACK_VARIABLES_ARGS);
}

函数就是通过参数 newthread 返回的线程 id,实现里直接把 pd 强转成 pthread_t 类型赋值给了 newthread。这个 pd 是什么类型呢?

int
__pthread_create_2_1 (newthread, attr, start_routine, arg)pthread_t *newthread;const pthread_attr_t *attr;void *(*start_routine) (void *);void *arg;
{STACK_VARIABLES;const struct pthread_attr *iattr = (struct pthread_attr *) attr;if (iattr == NULL)/* Is this the best idea?  On NUMA machines this could meanaccessing far-away memory.  */iattr = &default_attr;struct pthread *pd = NULL;int err = ALLOCATE_STACK (iattr, &pd);if (__builtin_expect (err != 0, 0))/* Something went wrong.  Maybe a parameter of the attributes isinvalid or we could not allocate memory.  Note we have totranslate error codes.  */return err == ENOMEM ? EAGAIN : err;

struct pthread 是一个结构体,记录线程信息的:

所以这个线程 id 就是一个地址(被强转成pthread_t,也就是 unsigned long int 类型值)值?用 GDB 看一下最清楚了:

这个 pd 指针的值就是 0x7ffff7fd8700,而这个值也是结构体里数据的首地址:

 

所以这个地址值转成 unsignd long int 是多少呢?强转后的十进制值就是 140737353975552。

 

 

就是执行程序里打印的线程 id。 所以 pthread_create() 返回的线程 id,其实就是保存线程信息的结构体的首地址。因此这个线程 id 是很重要的,其他线程相关函数可以通过这个 id 访问线程信息,如 pthread_t 强转为 struct pthread* 类型,其实 thread_id 就是一个地址:

int
pthread_getattr_np (thread_id, attr)pthread_t thread_id;pthread_attr_t *attr;
{struct pthread *thread = (struct pthread *) thread_id;struct pthread_attr *iattr = (struct pthread_attr *) attr;int ret = 0;lll_lock (thread->lock, LLL_PRIVATE);/* The thread library is responsible for keeping the values in thethread desriptor up-to-date in case the user changes them.  */memcpy (&iattr->schedparam, &thread->schedparam,sizeof (struct sched_param));iattr->schedpolicy = thread->schedpolicy;/* Clear the flags work.  */iattr->flags = thread->flags;/* The thread might be detached by now.  */if (IS_DETACHED (thread))iattr->flags |= ATTR_FLAG_DETACHSTATE;/* This is the guardsize after adjusting it.  */iattr->guardsize = thread->reported_guardsize;

这个函数就是获取指定线程的信息,其中当然包括用户设置的栈大小

所以要获取线程栈大小,需要使用两个函数调用:

 pthread_getattr_np(pthread_self(), &attr)

pthread_attr_getstacksize(&attr, &stack_size) 

http://www.yayakq.cn/news/399495/

相关文章:

  • 网站页面设计主要包括凡科建站怎么样
  • 广州做公司网站的公司有哪些网站排名优化外包价钱
  • 微信网站开发公司电话wordpress分类指定页面
  • 数据共享网站建设莒县网页定制
  • 公司建立网站流程图购物网站代码
  • 成都网站建设创新互联广州商城网站建设报价
  • 旅游营销型网站建设企业邮箱地址怎么注册
  • 单位的网站的建设怎么做好网络销售技巧
  • 共享经济型网站开发网络营销有几种方式
  • 上海企业网站建设补贴Wordpress虚拟资源下载类主题
  • 给别人做网站的销售叫什么网络营销的网站建设报告
  • 中国做水产的有什么网站网站描述
  • 电子商务网站的作用全国最大网站建站公司
  • 做彩票网站违法的吗中职示范校建设网站
  • 做网站方面手机上怎么制作网站吗
  • 官方网站怎么制作1免费建站网站
  • 在网站上上传文件需要怎么做书荒小说阅读器是哪个网站做的
  • 江苏省交通工程建设局网站农产品网络营销渠道
  • 抖音代运营协议书范本谷歌网站优化工具
  • 网站设计公司山东烟台优衣库网站建设的目的
  • 从化五屏网站建设抖音代运营公司合法吗
  • 天津网站设计成功柚米wordpress 表结构
  • 个人网站备案icpwordpress 全部页面500
  • 前端静态网站模板下载做网站用的产品展示横幅
  • 建设一个网站是不必须备案秦皇岛黄金海岸龙华园海景酒店
  • 网站建设 推广全流程大连招标网
  • 电商网站开发教材免费图片制作
  • wordpress美化文章内相册湘潭seo快速排名
  • 武进网站建设价位中核工建设集团网站
  • 如何做网站的注册页面电脑下载17zwd一起做网站