danvratil / qcoro

C++ Coroutines for Qt
https://qcoro.dvratil.cz
MIT License
331 stars 53 forks source link

Implement an awaitable `QMutex` #146

Open danvratil opened 1 year ago

danvratil commented 1 year ago

When using coroutines it's possible to easily reach a deadlock: thread acquires a lock and suspends, the event loop schedules another coroutine - if that coroutine will start waiting for the same lock a deadlock happens.

A solution is to have an awaitable mutex - one where acquiring a lock is an asynchronous operation as well, so that if the mutex is already locked, the coroutine is suspended and another one runs.