facebookexperimental / facebookexperimental/libunifex

lock_guard and async_mutex interactions

Open
#440 2 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
C++
Stars
1.7k
Forks
210
PR merge metrics
No merged PRs in 30d

Description

I was wandering if awaiting on an async_mutex should return a reference to async_mutex, then, it could be used together with lock_guard and unique_lock nicely (at least for initial acquisition).

https://godbolt.org/z/eKvYzxzTn

```c++
struct async_mutex {
async_mutex& async_lock() { return *this; }
void unlock() { puts("unlocked"); }
};
#define CO_AWAIT

int main() {
async_mutex mut;
{
std::lock_guard lock(CO_AWAIT mut.async_lock(), std::adopt_lock);
}
{
std::unique_lock lock(CO_AWAIT mut.async_lock(), std::adopt_lock);
}
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.