microsoft / arcana.cpp

Arcana.cpp is a collection of helpers and utility code for low overhead, cross platform C++ implementation of task-based asynchrony.
MIT License
78 stars 24 forks source link

Add suspend/resume capability to dispatcher #4

Open syntheticmagus opened 5 years ago

syntheticmagus commented 5 years ago

Add the ability to suspend and resume execution from another thread by setting state (or taking a token or something) on a dispatcher, without having to interact directly with mutexes or locks.

ryantrem commented 5 years ago

The base dispatcher class has a protected tick that derived classes call. manual_dispatcher exposes the tick publicly so the consumer can manually process queued work. For these cases, having a way to pause/resume doesn't make sense (since full control of synchronous ticking is already exposed). For background_dispatcher, tick is not exposed and all processing of the work queue is internal. For this case, I could imagine exposing a function from background_dispatcher that is something like: task<gsl::final_action<void>> pause(). The idea would be that it is an asynchronous request to pause the work queue (after finishing the current operation/tick if there is one), and returning a gsl::final_action that is used as a token such that when the caller destroys it, the work queue is resumed.