libunifex icon indicating copy to clipboard operation
libunifex copied to clipboard

What if the cancellation is an async operation?

Open Chlorie opened this issue 2 years ago • 2 comments

Sometimes the cancellation routine would require some asynchronous operations, for example, acquisition of mutexes, sending close packets, etc. Since the stop callback must be synchronous, I was scheduling the "real" asynchronous cancellation onto some async_scope, but this violates the structured concurrency idiom, since the original task might have finished and released its resources by the time the cancellation is run. Is there any good method to remedy this or am I using the wrong abstractions? Thanks!

Chlorie avatar Nov 19 '21 08:11 Chlorie

Generally the stop_callback would be destroyed when the underlying operation completes, and thus the callback is unregistered. If the callback happens to be executing concurrently with the completion of the operation then the destruction of the callback blocks until the the callback finishes executing (care needs to be taken to ensure this doesn't result in a deadlock).

lewissbaker avatar Apr 09 '22 23:04 lewissbaker

@Chlorie looks like the original question was addressed. Let's close unless you need more help.

janondrusek avatar Jul 29 '22 20:07 janondrusek