Skip to content

Commit 4ab2ad0

Browse files
committed
improve docs
1 parent 92548c1 commit 4ab2ad0

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

driver-core/src/main/com/mongodb/internal/async/function/AsyncCallbackLoop.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,17 @@ boolean run(final boolean trampolining, final SingleResultCallback<Void> afterLo
128128
// the happens-before relation, the execution contains a data race and the read is allowed to observe the write.
129129
// If such observation happens when the iteration is executed asynchronously, then we have a false positive.
130130
// Furthermore, depending on the nature of the value read, it may not be trustworthy.
131+
//
132+
// Making `trampoliningResult` a `volatile`, or even making it an `AtomicReference`/`AtomicInteger` and calling `compareAndSet`
133+
// does not resolve the issue: it gets rid of the data race, but still leave us with a race condition
134+
// that allows for false positives.
131135
boolean[] trampoliningResult = {false};
132136
sameThreadDetector.set(SameThreadDetectionStatus.PROBING);
133137
body.run((r, t) -> {
134138
if (completeIfNeeded(afterLoopCallback, r, t)) {
135139
// Bounce if we are trampolining and the iteration was executed synchronously,
136-
// trampolining completes and so is the whole loop;
137-
// otherwise, the whole loop simply completes.
140+
// trampolining completes and so is the loop;
141+
// otherwise, the loop simply completes.
138142
return;
139143
}
140144
if (trampolining) {

driver-core/src/test/unit/com/mongodb/internal/async/VakoTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class VakoTest {
4242

4343
@BeforeAll
4444
static void beforeAll() {
45-
executor = Executors.newScheduledThreadPool(2);
45+
executor = Executors.newScheduledThreadPool(1);
4646
}
4747

4848
@AfterAll

0 commit comments

Comments
 (0)