I have a method that gets called via a third party from IO service. My method is supposed to return a boolean. However, I need to post another task to the same IO service, and wait for it to complete before I know the result. How can I return control to the IO loop while I wait for the other task to finish?
(I can add multiple threads, but then there could be multiple calls to my methods, and you'd still end up with a deadlock)
Call graph before:
<thread> io_service third_party my_stuff
| | | |
|---run----->| | |
| |-->some_posted_method-->| |
| | |--callback-->|
| | |<--boolean---|
| |(next task) | |
| | | |
Call graph preferred:
<thread> io_service third_party my_stuff
| | | |
|---run----->| | |
| |-->some_posted_method-->| |
| | |--callback-->|
| |<----some_way_to_return_control-------|
| |(next task) | |
| |--------some_kind_of_resume---------->|
| | |<--boolean---|
| | | |