Boost.Atomic provides a unit test suite
to verify that the implementation behaves as expected:
-
fallback_api.cpp verifies that the fallback-to-locking
aspect of Boost.Atomic compiles and
has correct value semantics.
-
native_api.cpp verifies that all atomic
operations have correct value semantics (e.g. "fetch_add" really
adds the desired value, returning the previous). It is a rough "smoke-test"
to help weed out the most obvious mistakes (for example width overflow,
signed/unsigned extension, ...).
-
lockfree.cpp verifies that the BOOST_ATOMIC_*_LOCKFREE macros are set properly
according to the expectations for a given platform, and that they match
up with the is_always_lock_free and
is_lock_free members of the atomic object instances.
-
atomicity.cpp lets two threads race
against each other modifying a shared variable, verifying that the operations
behave atomic as appropriate. By nature, this test is necessarily stochastic,
and the test self-calibrates to yield 99% confidence that a positive
result indicates absence of an error. This test is very useful on uni-processor
systems with preemption already.
-
ordering.cpp lets two threads race against
each other accessing multiple shared variables, verifying that the operations
exhibit the expected ordering behavior. By nature, this test is necessarily
stochastic, and the test attempts to self-calibrate to yield 99% confidence
that a positive result indicates absence of an error. This only works
on true multi-processor (or multi-core) systems. It does not yield any
result on uni-processor systems or emulators (due to there being no observable
reordering even the order=relaxed case) and will report that fact.