Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic bitset is not thread safe #240

Open
JohanMabille opened this issue Jan 7, 2021 · 1 comment
Open

Dynamic bitset is not thread safe #240

JohanMabille opened this issue Jan 7, 2021 · 1 comment

Comments

@JohanMabille
Copy link
Member

JohanMabille commented Jan 7, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants