一旦 std:thread 进入 C++Ox,pthreads 就会过时吗

发布于 2024-07-30 13:00:27 字数 1433 浏览 2 评论 0原文

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

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

发布评论

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

评论(7

情话难免假 2024-08-06 13:00:27

C不会消失。 POSIX 不会消失。 用 C 编写的 POSIX 多线程代码不会消失。 所以 pthreads 不会消失。

std::thread 的许多实现都会在幕后使用 pthreads。

“Pthreads API 在 ANSI/IEEE POSIX 1003.1 - 1995 标准中定义。” -- POSIX 线程编程 https://computing.llnl.gov/tutorials/pthreads/

C isn't going away. POSIX isn't going away. Multithreaded code written in C for POSIX isn't going away. So pthreads isn't going away.

Many implementations of std::thread will use pthreads under the hood.

"The Pthreads API is defined in the ANSI/IEEE POSIX 1003.1 - 1995 standard." -- POSIX Threads Programming https://computing.llnl.gov/tutorials/pthreads/

东京女 2024-08-06 13:00:27

POSIX 是一种操作系统标准。 C++0X 是一种语言标准。 在第二个线程中使用线程不会使第一个线程过时。 两者之间存在协作,因此第二个可以在第一个的基础上实现。 (并且还有一个正在进行的工作,为 POSIX 提供 C++ 接口)。

POSIX is an operating system standard. C++0X is a language standard. Having threads in the second will not obsolete the first. There is a collaboration between the two so that the second is implementable on the first. (And there is also work in process to have a C++ interface for POSIX).

叶落知秋 2024-08-06 13:00:27

支持 pthread 的平台上的 C++ 实现可能会根据 pthread 实现语言功能 - 所以不,它不会过时。

C++ implementations on platforms that support pthreads will probably implement the language features in terms of pthreads - so no, it isn't going to be obsolete.

巷雨优美回忆 2024-08-06 13:00:27

std::thread 不包括对优先级、控制线程堆栈大小、控制调度策略或控制处理器关联的支持。

调度类和优先级对于实时系统至关重要。 处理器关联性和堆栈大小对于高性能系统非常重要。 此类应用程序将继续使用本机线程设施,也许除了 std::thread 之外,也许代替 std::thread,也许通过与 std::thread 一起公开所需功能的供应商扩展。

std::thread does not include support for priorities, controlling the size of the thread stack, controlling the scheduling policy, or controlling the processor affinity.

Scheduling class and priorities are crucial for real-time systems. Processor affinity and stack size are really important for high-performance systems. Such applications will either continue to use the native thread facilities, maybe in addition to std::thread, maybe instead of std::thread, maybe through vendor extensions that expose the needed features along with std::thread.

网名女生简单气质 2024-08-06 13:00:27

不管技术比较如何,花了十年的时间才从所有主要平台/供应商获得了相当不错的 C++ 98 支持。 仅此一点就确保了 pthreads 将在 2020 年变得强劲。

Regardless of technical comparisons, it took the best part of a decade to get even reasonably decent C++ 98 support from all major platforms/vendors. This alone ensures pthreads will be going strong in 2020.

昵称有卵用 2024-08-06 13:00:27

至少对于 boost 线程来说是正确的:

  • 它不支持堆栈大小参数
  • 它不支持 setpshared 属性

所以不......在 OS API 被视为过时之前还有一些事情要做。 (顺便说一句,线程是通过 pthread 实现的)

At least correct for boost thread:

  • It does not support stack size parameter
  • It does not support setpshared attribute

So no... There is some things to do before OS API could be considered obsolete. (and BTW threads are implemented over pthreads)

陌上芳菲 2024-08-06 13:00:27

也许对于新代码来说,使用标准中的内容将是正确的方法。 我们将不得不等待,看看主要编译器中的实现有多可靠。 但是,假设现有代码现在可以工作,那么从 pthread 转换现有代码不会有太大好处。 这包括在已经拥有丰富 pthread 经验的商店中编写的新代码。

Maybe for new code, using what is in the standard will be the right way to go. We will have to wait and see how solid the implementations in the major compilers are. But there won't be much benefit to converting existing code from pthreads, assuming it is working now. This includes new code written in a shop that already have a lot of experience with pthreads.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文