boostorg / boostorg/asio

Is this write protected by the lock?

Open
#412 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
1.6k
Forks
485
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.