- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
我想使用 std::atomic_bool
因为我想要一个应该被不同线程访问的 bool 值。
它是一个 static
成员变量。问题是我想用 false
作为第一个状态来初始化它。通常我会这样做:std::atomic_bool World::mStopEvent = false;
但问题似乎是它没有将 false
作为构造函数。那么我应该如何初始化这样一个变量呢?我正在使用 VS 2012。
最佳答案
这是 known issue in Visual Studio 2012 (known as VC11) ,您应该对现有的 Connect 项目进行投票,以便 Microsoft 知道它会影响更多人,因为他们推迟了修复。
Hi,
Thanks for reporting this bug. I'm Microsoft's maintainer of the STL, and I wanted to let you know that while this bug remains active in our database, it won't be fixed in VC11 RTM (VS 2012 RTM). All bugs are important to us, but some are more severe than others and rise to the top of our priority queue.
I'm copying-and-pasting this response across all of the STL's active Connect bugs, but the following terse comments apply specifically to your bug:
- Yep, we're missing these constructors on
atomic_bool
,atomic_int
, etc. (atomic<bool>
,atomic<int>
, etc. have them). 29.5 [atomics.types.generic]/7 says "There shall be named types corresponding to the integral specializations of atomic, as specified in Table 145, and a named typeatomic_bool
corresponding to the specifiedatomic<bool>
. Each named type is a eithertypedef
to the corresponding specialization or a base class of the corresponding specialization. If it is a base class, it shall support the same member functions as the corresponding specialization." which makes me really want to use typedefs (1 type is always simpler than 2 types), but I'll need to see if that would introduce any other issues.I can't promise when we'll be able to resolve this bug, but we hope to do so as soon as possible (and I'll send another response when that happens) - our first opportunity will be the "out of band" release between VC11 and VC12 that Herb Sutter announced at the GoingNative 2012 conference.
Note: Connect doesn't notify me about comments. If you have any further questions, please E-mail me.
Stephan T. Lavavej Senior Developer - Visual C++ Libraries stl@microsoft.com
基本上,您需要使用 std::atomic<T>
暂时。
关于c++ - 初始化 std::atomic_bool?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15750917/
我有两个线程和一个由第二个线程设置的标志。我可以使用 atomic_bool,但我希望能够等待* 在第一个线程上设置标志。我该怎么做? 我猜我不能使用condition_variable,因为如果第二
我正在阅读 Anthony Williams 的“C++ Concurrency in Action”,我看到了这段代码,它是线程池的简单实现。 class thread_pool { std
我有一个包含两个进程的程序,这些进程使用共享内存进行通信。在 ctrl-c 上,我希望两个进程都退出。我正在使用一个名为 stop 的 atomic_bool 变量来通知进程在设置为 true 时保持
我想使用 std::atomic_bool 因为我想要一个应该被不同线程访问的 bool 值。 它是一个 static 成员变量。问题是我想用 false 作为第一个状态来初始化它。通常我会这样做:s
朴素的 bool 否定 std::atomic_bool b; b = !b; 似乎不是原子的。我怀疑这是因为 operator! 触发了转换为纯 bool。一个人将如何原子地执行等效的否定?以下代码
如主题所述:vector涉及以与 vector 相同的方式合并 vector 元素? 最佳答案 没有。 std::vector只有一个专业,std::vector . bool和 std::atmoi
我有一个从套接字读取并生成数据的线程。每次操作后,线程都会检查一个 std::atomic_bool 标志以确定它是否必须提前退出。 为了取消操作,我将取消标志设置为true,然后在工作线程对象上调用
我正在尝试编译声明 std::atomic_bool 类型变量的 C++11 代码。这是在带有 clang 的 Mac OS 10.8.2 上: clang --version Apple clang
我正在使用 VC++ 编译我的程序(使用 Visual Studio 2015,更新 3),但一些片段无法编译。 基本上,我想绑定(bind)一个函数,该函数使用原子 bool 值获取对原子 bool
我是一名优秀的程序员,十分优秀!