diff options
Diffstat (limited to 'libphobos/src/std/concurrency.d')
-rw-r--r-- | libphobos/src/std/concurrency.d | 79 |
1 files changed, 41 insertions, 38 deletions
diff --git a/libphobos/src/std/concurrency.d b/libphobos/src/std/concurrency.d index d101ce4..a9830af 100644 --- a/libphobos/src/std/concurrency.d +++ b/libphobos/src/std/concurrency.d @@ -484,7 +484,7 @@ private template isSpawnable(F, T...) enum isParamsImplicitlyConvertible = false; } - enum isSpawnable = isCallable!F && is(ReturnType!F == void) + enum isSpawnable = isCallable!F && is(ReturnType!F : void) && isParamsImplicitlyConvertible!(F, void function(T)) && (isFunctionPointer!F || !hasUnsharedAliasing!F); } @@ -1573,10 +1573,9 @@ private: this.outer.yield(); } - private bool notified; + bool notified; } -private: void dispatch() { import std.algorithm.mutation : remove; @@ -1600,7 +1599,6 @@ private: } } -private: Fiber[] m_fibers; size_t m_pos; } @@ -1919,48 +1917,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; } /// @system unittest |