gpt4 book ai didi

c++ - 初始化 std::atomic_bool?

转载 作者:IT老高 更新时间:2023-10-28 12:29:48 33 4
gpt4 key购买 nike

我想使用 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 type atomic_bool corresponding to the specified atomic<bool>. Each named type is a either typedef 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/

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