Skip to content

Commit 322d9d4

Browse files
committed
update outdated comment
1 parent b286e5e commit 322d9d4

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/main/kotlin/net/robinfriedli/exec/MutexSync.kt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,10 @@ class MutexSync<K> {
1919
mutex = mutexMap.computeIfAbsent(key, { k: K -> ReferenceCountedMutex(k, mutexMap) })
2020
val currentRc = mutex.incrementRc()
2121

22-
// It is possible that some thread cleared the mutex just after this thread retrieved it from the map
23-
// but before this thread increments the rc. In this case the thread that removed the mutex also decremented
24-
// the rc again to a negative integer so we can check here whether the previous rc was indeed negative when
25-
// incrementing and retry getting the mutex. The order of these operations (the removing thread decrementing
26-
// rc twice then this thread incrementing rc) is guaranteed to be correct since incrementRc() and decrementRc()
27-
// are both synchronised methods.
22+
// An rc of 0 marks an invalid mutex that was or currently is being removed from the map, meaning the mutex
23+
// retrieved from the map was in the process of being removed by some other thread or at least before this
24+
// thread managed to increment the rc, now failing to do so because once the rc has reached 0 it cannot be
25+
// incremented. In this case the process of acquiring the mutex has to be retried.
2826
if (currentRc > 0) {
2927
break
3028
}

0 commit comments

Comments
 (0)