Skip to content

Commit

Permalink
Make helpRemove actually lock-free and address multiple chained remov…
Browse files Browse the repository at this point in the history
…ed nodes (Kotlin#2795)

* The previous version invoked correctPrev on the next node and bailed out fi it was removed, effectively blocking the progress of any attempts to remove previous node
    * Use helpRemovePrev in helpRemove that was actually implemented to avoid such problem

Fixes Kotlin#2590
  • Loading branch information
qwwdfsad authored and pablobaxter committed Sep 14, 2022
1 parent 00087a5 commit fca1fd4
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 7 deletions.
Expand Up @@ -259,7 +259,7 @@ public actual open class LockFreeLinkedListNode {
// Helps with removal of this node
public actual fun helpRemove() {
// Note: this node must be already removed
(next as Removed).ref.correctPrev(null)
(next as Removed).ref.helpRemovePrev()
}

// Helps with removal of nodes that are previous to this
Expand Down
2 changes: 1 addition & 1 deletion kotlinx-coroutines-core/jvm/test/AbstractLincheckTest.kt
Expand Up @@ -15,7 +15,7 @@ abstract class AbstractLincheckTest : VerifierState() {
open fun StressOptions.customize(isStressTest: Boolean): StressOptions = this

@Test
open fun modelCheckingTest() = ModelCheckingOptions()
fun modelCheckingTest() = ModelCheckingOptions()
.iterations(if (isStressTest) 100 else 20)
.invocationsPerIteration(if (isStressTest) 10_000 else 1_000)
.commonConfiguration()
Expand Down
Expand Up @@ -9,15 +9,10 @@ import kotlinx.coroutines.sync.*
import org.jetbrains.kotlinx.lincheck.*
import org.jetbrains.kotlinx.lincheck.annotations.Operation
import org.jetbrains.kotlinx.lincheck.strategy.managed.modelchecking.*
import org.junit.*

class MutexLincheckTest : AbstractLincheckTest() {
private val mutex = Mutex()

override fun modelCheckingTest() {
// Ignored via empty body as the only way
}

@Operation
fun tryLock() = mutex.tryLock()

Expand Down

0 comments on commit fca1fd4

Please sign in to comment.