According to the documentation, an atomic supports T that is of an integral type, enumeration type, or a pointer type. Does Intel TBB support floats/doubles officially? I have seen some patches here and by Raf Schietekat here, which might/might not have been incorporated into the latest 4.0 release. From the patches I have read through, the only major difference I noticed was the addition of reinterpret_cast from integer type to float/double. If anyone could clarify this, I would appreciate it. Thanks!
You can easily add support for floating-point numbers building on top of 64 and 32 bit atomic integers. Atomic load/store/exchange can be implemented as direct wrappers using reinterpret_cast, the atomic arithmetic operations can be implemented using a loop with atomic compare exchange.
C++11 supports atomic floats and doubles. Arithmetic functions like std::atomic_fetch_add
are only supported for integral types, though.
If you have a C++11 compiler, I would recommend to switch to std::atomic
so you don't have to rely on undocumented behavior.
The test for non-integral types in test_atomic.cpp was added back in 2008 (soon after the time of the discussion with Raf). Thus since even early than the time of the question, TBB supports float&double atomics (though restricted to fetch_and_store and compare_and_exchange read-modify-write ops only).
© 2022 - 2024 — McMap. All rights reserved.
std::atomic
. – Cristiecristin