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