Skip to content

Commit 6398c04

Browse files
committed
Add a comment about ConditionVariable#await and locks.
1 parent 8fa4400 commit 6398c04

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/main/java/org/truffleruby/core/mutex/ConditionVariableNodes.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,13 @@ private void awaitSignal(RubyConditionVariable self, RubyThread thread, long dur
158158
return BlockingAction.SUCCESS;
159159
}
160160

161+
/** Condition#await() can only exit (return or throw) after the associated ReentrantLock is
162+
* re-acquired. Even if it's interrupted, the InterruptedException is "stuck inside" until that
163+
* ReentrantLock is re-acquired. So the ReentrantLock we use here must be a ReentrantLock used
164+
* only for that Condition/RubyConditionVariable and nothing else. Specifically it must not be a
165+
* ReentrantLock exposed to Ruby, e.g., via a Ruby Mutex, as that could be held forever by
166+
* another Ruby thread (which did {code mutex.lock} after the #wait), and we would never be able
167+
* to interrupt both threads at the same time for a synchronous ThreadLocalAction). */
161168
condition.await(endNanoTime - currentTime, TimeUnit.NANOSECONDS);
162169
} else {
163170
condition.await();

0 commit comments

Comments
 (0)