Thread safety improvements in the task system.

Removes some invalid safety annotations and adds a workaround for a starvation issue in Task.join() across threads boundaries. This is still not thread-safe, but now has a safety-net and is documented, so that it doesn't get lost.
This commit is contained in:
Sönke Ludwig 2016-12-19 20:24:08 +01:00
parent 1b2c0f33d1
commit 8c0660781d
3 changed files with 42 additions and 34 deletions

View file

@ -735,9 +735,10 @@ void yield()
@safe {
auto t = Task.getThis();
if (t != Task.init) {
t.taskFiber.handleInterrupt();
auto tf = () @trusted { return t.taskFiber; } ();
tf.handleInterrupt();
s_scheduler.yield();
t.taskFiber.handleInterrupt();
tf.handleInterrupt();
} else {
// Let yielded tasks execute
() @safe nothrow { performIdleProcessing(); } ();
@ -763,9 +764,10 @@ void hibernate(scope void delegate() @safe nothrow on_interrupt = null)
if (t == Task.init) {
runEventLoopOnce();
} else {
t.taskFiber.handleInterrupt(on_interrupt);
auto tf = () @trusted { return t.taskFiber; } ();
tf.handleInterrupt(on_interrupt);
s_scheduler.hibernate();
t.taskFiber.handleInterrupt(on_interrupt);
tf.handleInterrupt(on_interrupt);
}
}