Grand Central Dispatch 中的线程数和线程数

发布于 2024-08-24 23:32:25 字数 141 浏览 3 评论 0原文

我正在使用 C 和 Grand Central Dispatch 来并行化一些繁重的计算。如何获取GCD使用的线程数?另外是否可以知道一段代码当前在哪个线程上运行?基本上我想对多个流使用sprng(并行随机数),为此我需要知道要使用什么流id(以及正在使用什么线程)。

I am using C and Grand Central Dispatch to parallelize some heavy computations. How can I get the number of threads used by GCD? Also is it possible to know on which thread a piece of code is currently running on? Basically I'd like to use sprng (parallel random numbers) with multiple streams and for that I need to know what stream id to use (and therefore what thread is being used).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤星 2024-08-31 23:32:25
  • 由于每个线程都有不同的运行循环,您可以通过 CFRunLoopGetCurrent() 获取当前运行循环,
  • 或者如果您使用的是 AppKit [NSThread currentThread];
  • 在 NSThread 上,您可以使用 - (NSMutableDictionary *)threadDictionary 添加任何其他对象以在同一线程上的调用之间共享,
  • 或者您可以使用 pthread API man pthread
  • as each thread has a different runloop you can get the current runloop by CFRunLoopGetCurrent()
  • or if you're using AppKit [NSThread currentThread];
  • on NSThread you can add any other object to share between calls on the same thread using - (NSMutableDictionary *)threadDictionary
  • or you can work on pthread API man pthread
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文