Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue 17037 - std.concurrency has random segfaults #5004

Merged
merged 1 commit into from
Oct 19, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Somewhat unclear, is this really the last life-signal of thread being spawned?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I made it so that the test result (failure/success) was communicated back to the main thread instead of relying on exceptions being re-thrown (like it had been previously.)


scheduler = new FiberScheduler;
scheduler.start(testdg);
assert(receiveOnly!bool());
scheduler = null;
}
///
@system unittest
Expand Down