From fca1fd46cc03d882804c316e310536177315cf8c Mon Sep 17 00:00:00 2001 From: Vsevolod Tolstopyatov Date: Tue, 27 Jul 2021 20:30:44 +0300 Subject: [PATCH] Make helpRemove actually lock-free and address multiple chained removed nodes (#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 #2590 --- .../jvm/src/internal/LockFreeLinkedList.kt | 2 +- kotlinx-coroutines-core/jvm/test/AbstractLincheckTest.kt | 2 +- .../jvm/test/lincheck/MutexLincheckTest.kt | 5 ----- 3 files changed, 2 insertions(+), 7 deletions(-) diff --git a/kotlinx-coroutines-core/jvm/src/internal/LockFreeLinkedList.kt b/kotlinx-coroutines-core/jvm/src/internal/LockFreeLinkedList.kt index caad1e3323..9bbc6dc9eb 100644 --- a/kotlinx-coroutines-core/jvm/src/internal/LockFreeLinkedList.kt +++ b/kotlinx-coroutines-core/jvm/src/internal/LockFreeLinkedList.kt @@ -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 diff --git a/kotlinx-coroutines-core/jvm/test/AbstractLincheckTest.kt b/kotlinx-coroutines-core/jvm/test/AbstractLincheckTest.kt index 2b4e91c02a..89bbbfd7ee 100644 --- a/kotlinx-coroutines-core/jvm/test/AbstractLincheckTest.kt +++ b/kotlinx-coroutines-core/jvm/test/AbstractLincheckTest.kt @@ -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() diff --git a/kotlinx-coroutines-core/jvm/test/lincheck/MutexLincheckTest.kt b/kotlinx-coroutines-core/jvm/test/lincheck/MutexLincheckTest.kt index f7f59eef5e..a278985fdd 100644 --- a/kotlinx-coroutines-core/jvm/test/lincheck/MutexLincheckTest.kt +++ b/kotlinx-coroutines-core/jvm/test/lincheck/MutexLincheckTest.kt @@ -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()