Skip to content

Commit

Permalink
Fix issue 17037 - std.concurrency has random segfaults
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterWaldron committed Jul 14, 2017
1 parent 8f98afc commit bc7550f
Showing 1 changed file with 39 additions and 34 deletions.
73 changes: 39 additions & 34 deletions std/concurrency.d
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit bc7550f

Please sign in to comment.