Skip to content

Commit 2d093c9

Browse files
Take each block's zero lock in the incremental start-age test hook (#437)
__hxcpp_gc_incremental_test(10), which IncrementalGcStartSweep calls between collections, read every block's start bits and object headers without a lock while the zeroing thread could be reclaiming the same block under its mZeroLock. The hook now holds each block's mZeroLock while it reads the block, as the incremental sweep does. Only HXCPP_GC_INCREMENTAL_TEST builds read blocks this way. In a 40-run TSan loop on the ubuntu-26.04 image, main had reports in 2 runs and this change in 0. Fixes #436
1 parent e204796 commit 2d093c9

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

‎src/hx/gc/Immix.cpp‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7263,7 +7263,16 @@ class GlobalAllocator
72637263
{
72647264
int oldest = 0;
72657265
for(int i=0;i<mAllBlocks.size();i++)
7266-
oldest = std::max(oldest, mAllBlocks[i]->maxStartAge());
7266+
{
7267+
BlockDataInfo *block = mAllBlocks[i];
7268+
// Runs between collections, while the zeroing thread may be
7269+
// reclaiming or zeroing the block under this lock
7270+
int expected = 0;
7271+
while (!block->mZeroLock.compare_exchange_weak(expected, 1))
7272+
expected = 0;
7273+
oldest = std::max(oldest, block->maxStartAge());
7274+
block->mZeroLock = 0;
7275+
}
72677276
return oldest;
72687277
}
72697278
#endif

0 commit comments

Comments
 (0)