https://issues.dlang.org/show_bug.cgi?id=20271
Issue ID: 20271
Summary: Handle forking in the GC
Product: D
Version: D2
Hardware: x86_64
OS: Linux
Status: NEW
Severity: normal
Priority: P1
Component: druntime
Assignee: [email protected]
Reporter: [email protected]
This problem currently never finishes execution:
////////////// test2817a.d //////////////
import core.stdc.stdlib : exit;
import core.sys.posix.sys.wait : waitpid;
import core.sys.posix.unistd : fork;
import core.thread : Thread;
void main()
{
foreach (t; 0 .. 10)
new Thread({
foreach (n; 0 .. 100)
{
foreach (x; 0 .. 100)
new ubyte[x];
auto f = fork();
assert(f >= 0);
if (f == 0)
exit(0);
else
waitpid(f, null, 0);
}
}).start();
}
/////////////////////////////////////////
Here the exit function (not _exit) calls finalizers, which includes shutting
down the GC. However, if the GC lock was being held while a fork happened, that
leaves the GC in an inconsistent state in the fork.
PR: https://github.com/dlang/druntime/pull/2817
--