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

Is this write protected by the lock? #412

Open
setharnold opened this issue Mar 29, 2023 · 0 comments
Open

Is this write protected by the lock? #412

setharnold opened this issue Mar 29, 2023 · 0 comments

Comments

@setharnold
Copy link

https://github.com/boostorg/asio/blob/46ed570aa36d1a665b0425e26d013e189b26515b/include/boost/asio/detail/conditionally_enabled_mutex.hpp#LL79-L87C6

    // Explicitly release the lock.
    void unlock()
    {
      if (locked_)
      {
        mutex_.unlock();
        locked_ = false;
      }
    }

Hello, I'm reviewing a package with Coverity and it points out that this locked_ = false; happens after the mutex is unlocked.

Is there something to prevent one thread calling lock(), another thread calling unlock(), and the order of operations going like this:

mutex_.unlock();
        mutex_.lock();
        locked_ = true;
locked_ = false;

Thanks

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

1 participant