Intel® oneAPI Threading Building Blocks
Ask questions and share information about adding parallelism to your applications when using this threading library.

TBB atomic support for float/doubles

drselee
Beginner
304 Views
According to the documnetation, TBB atomic is supported for integer/enum types/pointer types.
I took at the test driver test_atomic.cpp and one of the test cases calls the function called
TestAtomicFloat. Does this imply that fetch_and_store, etc. will work correctly for
floats/doubles?
0 Kudos
1 Reply
RafSchietekat
Valued Contributor III
304 Views
Yes, the documentation is just not up to date. Be careful when evaluating success for CAS (+0 and -0 are different for CAS but not for the equality operator, so using just the equality operator to compare the comparand with the return value instead of excluding -0 or using memcmp at least for the dubious cases you might erroneously evaluate a failed invocation as successful).

This is mentioned in tbb40_20120408oss/include/tbb/atomic.h: "Works for any type T that has the same size as an integral type, has a trivial constructor/destructor, and can be copied/compared by memcpy/memcmp."

(2012-05-21) Elaborated.
0 Kudos
Reply