Skip to content

Commit 760dbfc

Browse files
Simnclaude
andcommitted
Lock the GC root set while marking and visiting roots
GCAddRoot, GCRemoveRoot and the offset root functions take sGCRootLock, but the collector iterated sgRootSet and sgOffsetRootSet without it. Stopping the world doesn't protect these sets, because threads in GC free zones and unregistered threads can still add and remove roots. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 504403d commit 760dbfc

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

‎src/hx/gc/Immix.cpp‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4263,6 +4263,10 @@ class GlobalAllocator
42634263

42644264
hx::VisitClassStatics(inCtx);
42654265

4266+
{
4267+
// Threads in GC free zones, or not registered at all, can still add and remove roots
4268+
std::lock_guard<std::mutex> rootLock(*hx::sGCRootLock);
4269+
42664270
for(hx::RootSet::iterator i = hx::sgRootSet.begin(); i!=hx::sgRootSet.end(); ++i)
42674271
{
42684272
hx::Object **obj = *i;
@@ -4286,6 +4290,7 @@ class GlobalAllocator
42864290
*(char **)(i->first) = (char *)(obj) + offset;
42874291
}
42884292
}
4293+
} // rootLock
42894294

42904295
if (hx::sgFinalizers)
42914296
for(int i=0;i<hx::sgFinalizers->size();i++)
@@ -4709,6 +4714,8 @@ class GlobalAllocator
47094714

47104715
{
47114716
hx::AutoMarkPush info(&mMarker,"Roots","root");
4717+
// Threads in GC free zones, or not registered at all, can still add and remove roots
4718+
std::lock_guard<std::mutex> rootLock(*hx::sGCRootLock);
47124719

47134720
for(hx::RootSet::iterator i = hx::sgRootSet.begin(); i!=hx::sgRootSet.end(); ++i)
47144721
{

0 commit comments

Comments
 (0)