- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It seems that tbb::atomic variables don't have default initialisation. I was expecting that they would be default initialised to zero so that if I wrap a pointer inside a tbb::atomic, for example, it would be initialised to null. The TBB book also mentions this feature. Instead, I am constantly having to write code like tbb::atomic
The correction for this is trivial and I have already done so on my TBB copy but I though I would mention the issue in this forum in case I'm missing something terribly obvious.
Cheers,
manuel
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Maybe there could be a version of tbb::atomic that is not meant to be used at file scope that would remove this restriction and make initialisation more natural.
Cheers,
manuel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
"The compiler doesn't bother to initialise variables when in Release mode unless specifically told to."
Then it would not be implementing standard C++. Are you quite sure?
"Maybe there could be a version of tbb::atomic that is not meant to be used at file scope that would remove this restriction and make initialisation more natural."
It's a tricky issue. Not providing such a constructor probably helps avoid mistakes, but the last version of C++0x I've looked at does have them (along with a lot of other stuff I don't agree with), although I haven't verified whether the compiler does anything special there.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
An atomic
However, usually an instance of atomic
[cpp]struct Foo { atomicx; Foo() : x() {} };[/cpp]
The x() in the member initialization list forces x to be zero initialized. This feature of C++ was originally motivated by template writers who needed a way to initialize a member to a deterministic value, where the member might be instantiated as a user-defined type or a built-in type.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
struct Foo { tbb::atomic<double> x; Foo() : x() {} };
This does not work in Visual Studio 2010. The double value in x is not initialized.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
That's not good...
How about x(tbb::make_atomic<double>(0.0))? Or simply x(0.0) (only with C++11)?
Debug and/or release?
double and/or int?
What's the TBB version?
(Added 2013-10-29) TestValueInitialization in src/test/test_atomic.cpp is supposed to verify this (although testing all bytes would be better than just the first one), so this seems very strange indeed. Perhaps the test should be extended to also specifically verify member variable initialisation if this pans out, to guard against a misbehaving compiler.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page