Comment #0 by dlang-bugzilla — 2019-10-06T13:53:28Z
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
Comment #1 by dlang-bot — 2019-10-06T14:03:43Z
@CyberShadow updated dlang/druntime pull request #2817 "Add fork handling to GC" fixing this issue:
- Add fork handling to GC
Make sure a fork does not happen while GC code is running, thus
leaving it in an inconsistent state.
Does not yet fix Druntime's thread list after a fork, so garbage
collection inside the forked process will still fail.
Fixes issue #20271.
https://github.com/dlang/druntime/pull/2817
Comment #2 by dlang-bot — 2019-10-07T11:21:32Z
dlang/druntime pull request #2817 "Add fork handling to GC" was merged into stable:
- 2ed4a03511de49644d9cb17152685a05d2d91b58 by Vladimir Panteleev:
Add fork handling to GC
Make sure a fork does not happen while GC code is running, thus
leaving it in an inconsistent state.
Does not yet fix Druntime's thread list after a fork, so garbage
collection inside the forked process will still fail.
Fixes issue #20271.
https://github.com/dlang/druntime/pull/2817