File tree Expand file tree Collapse file tree 1 file changed +4
-6
lines changed
src/main/kotlin/net/robinfriedli/exec Expand file tree Collapse file tree 1 file changed +4
-6
lines changed Original file line number Diff line number Diff line change @@ -19,12 +19,10 @@ class MutexSync<K> {
19
19
mutex = mutexMap.computeIfAbsent(key, { k: K -> ReferenceCountedMutex (k, mutexMap) })
20
20
val currentRc = mutex.incrementRc()
21
21
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.
28
26
if (currentRc > 0 ) {
29
27
break
30
28
}
You can’t perform that action at this time.
0 commit comments