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

Make async_mutex::lock_async behaviour more explicit by introducing a scoped_lock_async() method #18

Closed
lewissbaker opened this issue Jun 19, 2017 · 1 comment

Comments

@lewissbaker
Copy link
Owner

lewissbaker commented Jun 19, 2017

The async_mutex::lock_async() method currently has the dual behaviour of allowing you to lock the mutex in such a way that requires manual unlocking (ie. no RAII) as well as allowing you to encapsulate the lock in an async_mutex_lock object that will ensure the lock is released when the lock object goes out of scope.

The behaviour is currently chosen based on whether the caller assigns the result of the co_await m.lock_async() expression to an async_mutex_lock variable.

task<T> f(async_mutex& m)
{
  // Needs manual unlocking
  co_await m.lock_async(); 
  m.unlock();
}

task<T> g(async_mutex& m)
{
  // Lock encapsulated in RAII object
  async_mutex_lock lock = co_await m.lock_async(); 
}

This seems potentially error-prone way of doing things.

Consider having lock_async() always require manual unlocking and introduce a new scoped_lock_async() that returns an async_mutex_lock object.

@lewissbaker
Copy link
Owner Author

Addressed in 1140628

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