Skip to content

Commit 161b33f

Browse files
committed
Ensure that we always have at least two leaf nodes
1 parent 9697006 commit 161b33f

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/Concurrency/WorkContractGroup.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ namespace Concurrency {
2525
// Helper function to create appropriately sized SignalTree
2626
std::unique_ptr<SignalTreeBase> WorkContractGroup::createSignalTree(size_t capacity) {
2727
size_t leafCount = (capacity + 63) / 64;
28-
size_t powerOf2 = roundUpToPowerOf2(leafCount);
28+
// Ensure minimum of 2 leaves to avoid single-node tree bug
29+
// where the same node serves as both root counter and leaf bitmap
30+
size_t powerOf2 = std::max(roundUpToPowerOf2(leafCount), size_t(2));
2931

3032
return std::make_unique<SignalTree>(powerOf2);
3133
}

0 commit comments

Comments
 (0)