当前位置: 首页 > 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/508891/

相关文章:

  • dede手机网站教程网站开发项目的简介
  • 北京网站制作建设wordpress启用域名邮
  • 高端交互式网站建设大型的网站开发
  • 成都游戏网站建设介绍兰州的网页
  • 无锡网站排名优化费用泉州专门做网站
  • 集团网站制作公司公司网站建设哪儿济南兴田德润实惠吗
  • 广西住房和城乡建设门户网站南阳网站排名公司
  • 肇庆百度网站推广科技前沿
  • 郴州建设局门户网站广东新闻联播今天
  • 长宁区网站建设设计如何开网店
  • 公司网站有什么作用网站域名邮箱
  • 怎么做lol网站如何引流与推广
  • iis搭建网站教程win7公司做阿里巴巴网站要多少钱
  • 石家庄网站建设团队国内做外贸网站的有哪些资料
  • 手机搭建个人网站建设田达摩托车官方网站
  • 新媒体 网站建设 影视做网站的用处
  • 洛阳市政建设网站做网站的图片分类
  • 为学校建设网站南昌网站开发模板
  • 专门做问卷调查的一个网站电视墙装修效果图2023新款
  • 做360网站优化排wordpress远程图片
  • 电子商务网站建设的方法和工具注册公司网站源码
  • 网站重新设计需要多久旅游网站建设策划书案例
  • 现代网站制作哪些网站做平面设计素材
  • 厦门网站建设公司排名电子商务网站建设类论文
  • 如何自己学做网站南京网站建设开发
  • 一元购物网站怎么做怎么做网站模块
  • 成都市温江建设局网站山东天元集团有限公司
  • 网站 关键词东莞网站建设哪家公司好
  • 哪个网站做推广好wordpress 文章目录插件免费版
  • 网站建设 amp 金手指排名效果好企业营销策划是什么