Let's say we have two thread writing values into a dynamic bitset. If the thread tries to change bits stored in the same underlying integer, we may have a race condition in the following code:
template <class B, bool C>
inline void xbitset_reference<B, C>::set() noexcept
{
m_block |= m_mask;
}
This line is equivalent to m_block = m_block | m_mask.
Here m_block is a reference to the underlying integer used to store a group of bits. The issue is that Thread_1 may compute m_block | m_mask then Thread_2 computes m_block | m_mask and assigns it to m_block. Then Thread_1 writes m_block and overwrites the bit previously computed by Thread_2.
Let's say we have two thread writing values into a dynamic bitset. If the thread tries to change bits stored in the same underlying integer, we may have a race condition in the following code:
This line is equivalent to
m_block = m_block | m_mask.Here
m_blockis a reference to the underlying integer used to store a group of bits. The issue is that Thread_1 may computem_block | m_maskthen Thread_2 computesm_block | m_maskand assigns it tom_block. Then Thread_1 writesm_blockand overwrites the bit previously computed by Thread_2.