gpt4 book ai didi

c++ - C++11 认为 "thread"是什么?

转载 作者:IT老高 更新时间:2023-10-28 23:20:37 26 4
gpt4 key购买 nike

C++11 有一些线程的概念。例如,它定义了一个新的存储说明符 thread_local ,并指定对于具有此存储说明符的变量,“每个线程都有一个不同的对象或引用”[basic.stc.thread]。

为此目的,什么被视为“线程”?是否只有使用标准线程库创建的线程(即由 std::thread 对象表示的线程)?通过其他方式创建的线程(例如,直接在 Linux 上使用 pthreads)呢?如果我使用提供用户空间线程的库怎么办?每个线程都有自己的 thread_local 拷贝吗?对象(我真的不明白如何实现)?

如果答案是“它是由实现定义的,出于诸如 thread_local 之类的目的而被视为线程”,有人可以举一个例子来说明一个众所周知的实现是如何定义的吗?

最佳答案

只有来自线程的组件支持库计数,因为这些引号,或标准状态在其自己的执行线程中运行的 main

1 The following subclauses describe components to create and manage threads (1.10), perform mutual exclusion, and communicate conditions and values between threads, as summarized in Table 148.

到 1.10 的链接意味着正在谈论的线程就是这些。

1 A thread of execution (also known as a thread) is a single flow of control within a program, including the initial ...

因此,在我看来,threads 仅指 stdlib 线程(意味着 std::thread 以及线程支持库在内部执行的任何操作)。当然 thread_local 在许多情况下最终可能会使用 native 线程(尤其是当您考虑在特定系统上实现线程时通常不会有多个选择),但据我所知告诉标准不做任何保证。

关于c++ - C++11 认为 "thread"是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19759983/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com