Sometimes a situation arises when you really really want to have two atomic
operations occur atomically. However, performing two atomic operations on two
totally different atomic variables is not an atomic operation.
A nice technique that allows you to perform the type of action that is needed, is
to embed additional data into one std::atomic variable. By embedding additional data,
we are able to treat the operation as indeed, an atomic operation.
For example, we would want to store a bool and a count.
What we end up with, is this embedded atomic structure acting as a semaphore.
Be First to Comment