I want to use std::atomic_bool
because I want to have a boolean which is supposed to be accessed by different threads.
It's a static
member Variable. The Problem is that I want to initialize it with false
as the first state. Normally I would do it like that:
std::atomic_bool World::mStopEvent = false;
But the problems seems to be that it doesn't take false
as the constructor. So how I am supposed to initialize such a variable?
I am using VS 2012.
This is a known issue in Visual Studio 2012 (known as VC11), you should vote on the existing Connect item so that Microsoft knows it affects more folks as they've deferred the fix.
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 [email protected]
Basically, you'll need to use std::atomic<T>
for now.