
"Peter Dimov" <pdimov@pdimov.com> writes:
Anthony Williams:
One way to do this is have the pool use packaged_tasks internally, and set a wait callback which is invoked when a thread waits on a future from a pool task. When the callback is invoked by the waiting thread (as part of the call to wait()), if that waiting thread is a pool thread, it can proceed as above.
It actually doesn't matter whether the waiting thread is a pool thread or not. If the task hasn't been scheduled, it can be "stolen" and executed synchronously from within the wait().
Yes, you could do that. I'm not convinced it's necessarily a good idea, though. Different threads potentially have different priorities or access permissions. Also, thread interruption will behave differently: in my prototype implementation, future::wait() is an interruption point. If a call to wait() stole a task from a thread pool, interrupting the thread would instead interrupt the task, which is not necessarily what was intended, as this may have consequences for other threads waiting on that task. Anthony -- Anthony Williams | Just Software Solutions Ltd Custom Software Development | http://www.justsoftwaresolutions.co.uk Registered in England, Company Number 5478976. Registered Office: 15 Carrallack Mews, St Just, Cornwall, TR19 7UL