From bc7550fe8489e9ef913d9fe59dcdf63bb0501abb Mon Sep 17 00:00:00 2001 From: WalterW Date: Wed, 4 Jan 2017 16:19:59 -0500 Subject: [PATCH] Fix issue 17037 - std.concurrency has random segfaults --- std/concurrency.d | 73 +++++++++++++++++++++++++---------------------- 1 file changed, 39 insertions(+), 34 deletions(-) diff --git a/std/concurrency.d b/std/concurrency.d index 397c9d76c82..79ae5b084fe 100644 --- a/std/concurrency.d +++ b/std/concurrency.d @@ -1625,48 +1625,53 @@ void yield(T)(T value) import core.exception; import std.exception; - static void testScheduler(Scheduler s) - { - scheduler = s; - scheduler.start({ - auto tid = spawn({ - int i; - - try + auto mainTid = thisTid; + alias testdg = () { + auto tid = spawn( + (Tid mainTid) { + int i; + scope (failure) mainTid.send(false); + try + { + for (i = 1; i < 10; i++) { - for (i = 1; i < 10; i++) + if (receiveOnly!int() != i) { - assertNotThrown!AssertError(assert(receiveOnly!int() == i)); + mainTid.send(false); + break; } } - catch (OwnerTerminated e) - { - - } - - // i will advance 1 past the last value expected - assert(i == 4); - }); - - auto r = new Generator!int({ - assertThrown!Exception(yield(2.0)); - yield(); // ensure this is a no-op - yield(1); - yield(); // also once something has been yielded - yield(2); - yield(3); - }); - - foreach (e; r) + } + catch (OwnerTerminated e) { - tid.send(e); + // i will advance 1 past the last value expected + mainTid.send(i == 4); } + }, mainTid); + auto r = new Generator!int( + { + assertThrown!Exception(yield(2.0)); + yield(); // ensure this is a no-op + yield(1); + yield(); // also once something has been yielded + yield(2); + yield(3); }); - scheduler = null; - } - testScheduler(new ThreadScheduler); - testScheduler(new FiberScheduler); + foreach (e; r) + { + tid.send(e); + } + }; + + scheduler = new ThreadScheduler; + scheduler.spawn(testdg); + assert(receiveOnly!bool()); + + scheduler = new FiberScheduler; + scheduler.start(testdg); + assert(receiveOnly!bool()); + scheduler = null; } private