[D-runtime] A cooperative suspension API
Alex Rønne Petersen
xtzgzorex at gmail.com
Fri May 4 21:45:35 PDT 2012
Hi,
Another feature I want to implement in core.thread is cooperative
suspension. In this model, the thread_suspendAll() routine flips a global
variable that notifies all threads that they need to suspend. Now, a thread
that has marked itself as cooperative is then expected to regularly check
this variable and, when it notices that it needs to suspend, does so. This
means that the suspension machinery trusts cooperative threads to read this
global variable as fast as possible (note that races in reading the
variable are acceptable).
The question is how the API should work. I have something like this in mind:
class Thread
{
// ...
private bool m_isCooperative;
@property final bool isCooperative()
{
return m_isCooperative;
}
@property final void isCooperative(bool value)
{
synchronized (slock) // needed because changing this value can
affect the entire suspension process
{
m_isCooperative = value;
}
}
}
thread_suspendAll() then trivially checks Thread.m_isCooperative and makes
appropriate decisions (i.e. suspend all cooperative threads first and so
on).
Any thoughts?
Regards,
Alex
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/d-runtime/attachments/20120505/7fbe9943/attachment.html>
More information about the D-runtime
mailing list