I’m unsure how to approach the problem of shutting down persistent threads safely. In the case where each thread has its own local work queue, where overflows are spilled to a global work queue guarded by a lock, and exhausted local work queues cause work to be stolen from the global queue. And where each thread in processing work will generate zero to some set number of work items (Tree traversal type stuff for example).
Papers I have come across that appear to touch on this don’t have any specific details how to do this. I have only seen cases where an upper bound on total work is statically decided which of course may cause waste and is not easily determined in most cases.
The only other guaranteed way I can think of is to use a clock based bail out if idle period which isn’t ideal either and will cause waste.
Any other attempt of mine so far to use atomic based schemes of protocols/messaging has major flaws.