首页 \ 问答 \ 我如何从任意pthread_t获取线程ID?(How do I get a thread ID from an arbitrary pthread_t?)

我如何从任意pthread_t获取线程ID?(How do I get a thread ID from an arbitrary pthread_t?)

我有一个pthread_t,我想改变它的CPU亲和力。 问题是我使用glibc 2.3.2,它没有pthread_setaffinity_np() 。 不过,这很好,因为pthread_setaffinity_np()本身就是sched_setaffinity()的包装,可以通过传递线程ID而不是进程ID来设置任意线程的关联来调用它。

但是 ... sched_setaffinity可以使用的线程ID是一个操作系统线程ID,可以从gettid()系统调用中获得。 这与opaque类型pthread_t不同 ,gettid()只会返回当前线程的线程ID。 我需要能够设置任意线程的CPU亲和力。

不幸的是,我无法访问pthread的私有部分,这会让我通过将pthread_t转换为struct pthread *来窃取线程id。 我想,所有的更好,因为依赖私有实现需要更多的麻烦。

我也一直在阅读pthread_getunique_np函数,但是这会返回一个“唯一的整型标识符” - 我不认为它以任何形式或形式等同于操作系统线程ID。

因此,问题:我如何从任意pthread_t获取线程ID?


I have a pthread_t, and I'd like to change its CPU affinity. The problem is that I'm using glibc 2.3.2, which doesn't have pthread_setaffinity_np(). That's OK, though, because pthread_setaffinity_np() is itself a wrapper of sched_setaffinity(), which can be called by passing a thread ID instead of a process ID to set the affinity for an arbitrary thread.

BUT ... The thread id that sched_setaffinity can work with is an OS thread id, the kind that you can get from the gettid() system call. This is different from the opaque type pthread_t, and gettid() will only return the thread-id of the current thread. I need to be able to set the CPU affinity of an arbitrary thread.

Unfortunately, I can't access the pthread's private parts, which would let me steal the thread id by casting a pthread_t to a struct pthread *. All the better, I guess, since relying on private implementations is asking for even more trouble.

I've also been reading up on the pthread_getunique_np function, however this returns a "unique integral identifier" -- which I don't believe is in any way shape or form equivalent to an OS thread id.

Hence, the question: How can I get a thread ID from an arbitrary pthread_t?


原文:https://stackoverflow.com/questions/558469
更新时间:2022-06-09 21:06

最满意答案

ios 的rss app最好订阅的有
slide Reader
Reeder
MobileRSS
鲜果联播
Taptu
Byline
FLUD
News Gallery
腾讯订阅

其他回答

ios::nocreat 打开一个已有的文件,如文件不存在,则打开失败,nocreate的意思是不建立新文件    是非标准的,无替代品;
ios::app 追加模式打开文件夹,  以ios::app打开,如果没有文件,那么生成空文件;如果有文件,那么在文件尾 追加

相关问答

更多
  • RSS订阅是站点用来和其他站点之间共享内容的一种简易方式,即Really Simple Syndication(易信息聚合)。   在门户网站大行其道,人们已经习惯通过搜索引擎来获取新闻资讯的今天,一种全新的资讯传播方式已经悄悄地来到身边,仔细观察一些网站,可能注意到一些被标记为"XML"或"RSS"的橙色图标。   面对扑面而来的新闻,不用再花费大量的时间冲浪和从新闻网站下载,只要通过下载或购买一种小程序,这种被简称为RSS的技术会收集和组织定制的新闻,按照你希望的格式、地点、时间和方式,直接传送到计算机 ...
  • ios 的rss app最好订阅的有 slide Reader Reeder MobileRSS 鲜果联播 Taptu Byline FLUD News Gallery 腾讯订阅
  • RSS聚合本身是一种被新闻行业喜爱的,用于快速更新时效性强的咨询的消息来源格式规范 这是一种格式,和网页什么类似的,可以被你的浏览器所识别和添加。它不是某个网站或程序,不是直接操作RSS软件或者网页进行搜索设置的 你必须先找到一个支持RSS订阅(现在,如新浪、17173等带新闻媒体的网站都支持)的相关新闻/博客网站,然后在你的浏览器(我用的傲游有很方便的RSS支持)中添加
  • RSS订阅怎么用?[2023-12-04]

    什么是RSS? RSS是站点用来和其他站点之间共享内容的一种简易方式(也叫聚合内容),通常被用于新闻和其他按顺序排列的网站,例如Blog。一段项目的介绍可能包含新闻的全部介绍等。或者仅仅是额外的内容或者简短的介绍。这些项目的链接通常都能链接到全部的内容。网络用户可以在客户端借助于支持RSS的新闻聚合软件(如FeedDemon、SharpReader,NewzCrawler),在不打开网站内容页面的情况下阅读支持RSS输出的网站内容。网站提供RSS输出,有利于让用户发现网站内容的更新。 RSS如何工作? 首先 ...
  • 1、方便、快捷、集中和高效。只要登陆一个网站,你就可以把你所喜欢看的内容全部聚合在一起,而且是实时更新的。尤其当你关注某个事件的时候,你没必要不停的刷新网页或者通过搜索不停的寻找。2、无广告。到目前为止,99%的RSS是没用广告的。博客在rss中暂时没放入广告,不过以后可能会放。3、个性化。每个人的需求都是不同的,通过RSS订阅,你可以只关注你喜欢和想关注的内容,其余的一切,全部跟你无关。 第三:
  • Apple对允许在后台执行哪些应用程序有严格的规定。 不幸的是,您的应用不适合任何这些类别。 audio - 应用程序在后台播放可听内容给用户。 (此内容包括使用AirPlay播放音频或视频内容。) location - 该应用程序可让用户随时了解其位置,即使它在后台运行也是如此。 voip - 该应用程序使用户能够使用Internet连接拨打电话。 报亭 - 内容 - 该应用程序是一个报亭应用程序,可在后台下载和处理杂志或报纸内容。 external-accessory - 该应用程序与硬件附件配合使用, ...
  • 根据RFC822 ,时区应该是PST,或者符合以下格式: zone = "UT" / "GMT" ; Universal Time ; North American : UT / "EST" / "EDT" ; Eastern: - 5/ - 4 / "CST" / "CDT" ...
  • 您必须实现自定义子类UITableViewCell并包含两个附加属性rssDate和authorName 。 如果您已经在使用UITableViewCell自定义子类,那么请考虑添加这两个属性(也许,作为UILabel ) 编辑 要获取RSSDate和AuthorName请在XML查看其标记,并解析与解析Feed的Title相同的方式。 没有人能告诉你,如何在不看到XML结构的情况下解析这两者。 You have to implement custom subclass UITableViewCell an ...
  • 据我所知你不能。 iOS不是Android,您可以在其中选择默认应用来打开某些内容。 您可以创建共享扩展,因此当用户选择共享RSS链接URL时,您的应用程序将处理该链接。 As far as i know you can't. iOS is not Android, where you can select the default app to open something. You can create a Share Extension, so when the user selects to shar ...
  • 看看这个链接: https : //developer.apple.com/library/ios/documentation/FileManagement/Conceptual/DocumentInteraction_TopicsForIOS/Articles/RegisteringtheFileTypesYourAppSupports.html 这似乎是你在寻找的东西 Solved this issue with the help of feed URL scheme. Moreover, you ha ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。