Hi,<div><br></div><div>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).</div>
<div><br></div><div>The question is how the API should work. I have something like this in mind:</div><div><br></div><div>class Thread</div><div>{</div><div> // ...</div><div><br></div><div> private bool m_isCooperative;</div>
<div><br></div><div> @property final bool isCooperative()</div><div> {</div><div> return m_isCooperative;</div><div> }</div><div><br></div><div> @property final void isCooperative(bool value)</div><div>
{</div><div> synchronized (slock) // needed because changing this value can affect the entire suspension process</div><div> {</div><div> m_isCooperative = value;</div><div> }</div><div>
}</div><div>}</div><div><br></div><div>thread_suspendAll() then trivially checks Thread.m_isCooperative and makes appropriate decisions (i.e. suspend all cooperative threads first and so on).</div><div><br></div><div>
Any thoughts?</div><div><br></div><div>Regards,</div><div>Alex</div>