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 authored and RazvanN7 committed Oct 16, 2021
1 parent dc69783 commit 2c6051d
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 @@ -1919,48 +1919,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
Expand Down

0 comments on commit 2c6051d

Please sign in to comment.