-
Notifications
You must be signed in to change notification settings - Fork 108
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
example yield.hpp possibly destroys locked mutex #99
Comments
Because you did not mention the code lines I assume you refer to the implementation of yield_completion::wait(). The fiber calling this function locks the mutex (that protects variable completed_) and the suspends if the work was not completed yet. |
exactly, however, when suspend returns, it does not reaquire the lock, which is needed for safety |
Why should it acquire the lock again - the variable isn't required to protected again. |
I'll try to make it as clear as I can. The thread that calls The thread that created the lock then resumes. Note that the notifying thread might still hold the lock. It might have been suspended from execution by the OS or whatever. The notifying thread never releases the lock, yet it is destroyed. I assumed that on return of this might explain what im saying. |
Can confirm this is an issue in
I also assumed this, and am surprised it's not the case (especially when this function is not documented). The current fix we're trying over the weekend is to add |
fibers::context is not part of public the public API, it should not be used by the users. I'm focused on other parts of the library - so I've no time to take care for the asio binding. |
Yeah, we're running asio and the fibers in different threads to avoid the main-loop annoyance / integrate better with existing code. It seems weird that |
The problem is not related to the lock - the problem is that yield_completion is shared between async_result and yield_handler. It should go out of scope if the last reference (yield_handler or async_result) goes out of scope. Using an intrusive poitner should fix the issue. |
- in context of #99: example yield.hpp possibly destroys locked mutex
- in context of #99: example yield.hpp possibly destroys locked mutex
- in context of #99: example yield.hpp possibly destroys locked mutex
- in context of #99: example yield.hpp possibly destroys locked mutex
- in context of #99: example yield.hpp possibly destroys locked mutex
- in context of #99: example yield.hpp possibly destroys locked mutex
- in context of #99: example yield.hpp possibly destroys locked mutex
- in context of #99: example yield.hpp possibly destroys locked mutex
- in context of #99: example yield.hpp possibly destroys locked mutex
- in context of boostorg#99
I posted this on the boost bugtracker however it wasnt noticed by anyone, so ill post it here.
In the examples/asio/detail/yield.hpp file, the sleeping fiber owns the mutex(for when
async_result::get
returns, the asio call returns and the yield_completion is destroyed).Consider Fiber A, the callee of the async operation, and Fiber B, the fiber that calls async_handler.
Fiber B possibly runs in another thread.
Fiber B locks the mutex, sets fiber A as ready and goes to sleep without releasing the lock. Fiber A goes through the return process and destroys the mutex.
The solution is very simple. Simply reaquire the lock after the
suspend
call returns.The text was updated successfully, but these errors were encountered: