Conversation
002afd4 to
13822b4
Compare
src/gc/impl/conservative/gc.d
Outdated
There was a problem hiding this comment.
I think this pointer should be reset before gcx is destroyed. BTW: as only members of gcx are affected, how about moving this and the initialization into Gcx.Dtor and initialize, respectively?
There was a problem hiding this comment.
The lock is in ConservativeGC, and we need to refer to it from the callbacks. Accessing ConservativeGC from Gcx seemed to me like a layering violation, but I see now there is precedent.
63fb658 to
f593df9
Compare
|
I found a new bug while playing around to create a test case for this PR. import core.stdc.stdio : printf;
import core.stdc.stdlib : exit;
import core.sys.posix.sys.types : pid_t;
import core.sys.posix.sys.wait : waitpid;
import core.sys.posix.unistd : fork;
import core.thread : Thread, getpid;
extern(C) int syscall(int, ...);
pid_t gettid() { return syscall(186/*SYS_gettid*/); }
void main()
{
foreach (t; 0 .. 10)
new Thread({
auto parent = gettid();
foreach (n; 0 .. 100)
{
foreach (x; 0 .. 100)
new ubyte[x];
auto child = fork();
assert(child >= 0);
if (child == 0)
{
child = gettid();
printf("%d has forked.\n", child);
foreach (x; 0 .. 100)
new ubyte[x];
printf("%d is exiting.\n", child);
exit(0);
}
else
{
printf("%d waiting on %d...\n", parent, child);
waitpid(child, null, 0);
printf("%d done waiting on %d.\n", parent, child);
}
}
}).start();
}This program doesn't exit for me, because some threads are locked in a |
fdd2271 to
b04d060
Compare
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.
b04d060 to
2ed4a03
Compare
|
Thanks for your pull request, @CyberShadow! Bugzilla references
Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub fetch digger
dub run digger -- build "stable + druntime#2817" |
| { | ||
| if (instance) | ||
| ConservativeGC.gcLock.unlock(); | ||
| } |
There was a problem hiding this comment.
I will probably later move these out to a general Druntime fork handler which also takes care of the thread stuff.
There was a problem hiding this comment.
That probably won't work as the GC can be swapped out at link time.
There was a problem hiding this comment.
Not sure what you mean. The atfork notifications would then be part of the abstract GC interface.
Make sure a fork does not happen while GC code is running, thus leaving it in an inconsistent state.