From 288f3df7547eebd1f27d66dd3582b93f424809ba Mon Sep 17 00:00:00 2001 From: Ilya Matveev Date: Mon, 10 Jan 2022 18:55:24 +0700 Subject: [PATCH 1/2] Make multithreadingSupported a property with a getter This change fixes an issue with initialization order observed when lazy initialization is disabled (-Xir-property-lazy-initialization= disabled compiler flag) and the new MM is used. The problem is the following: the initialization of DefaultDelay happens before initialization of multithreadingSupported. Thus the initialization of DefaultDelay gets an uninitialized value of multithreadingSupported and behaves as if the old MM is used. Related issue: #KT-50491. --- kotlinx-coroutines-core/native/src/internal/Concurrent.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kotlinx-coroutines-core/native/src/internal/Concurrent.kt b/kotlinx-coroutines-core/native/src/internal/Concurrent.kt index 1db6c3bd86..9a3fd3c44e 100644 --- a/kotlinx-coroutines-core/native/src/internal/Concurrent.kt +++ b/kotlinx-coroutines-core/native/src/internal/Concurrent.kt @@ -32,6 +32,6 @@ internal open class SuppressSupportingThrowableImpl : Throwable() { } } -@SharedImmutable @OptIn(ExperimentalStdlibApi::class) -internal val multithreadingSupported: Boolean = kotlin.native.isExperimentalMM() +internal val multithreadingSupported: Boolean + get() = kotlin.native.isExperimentalMM() From aaee114fb2a43091cdccc5942c001906947df05c Mon Sep 17 00:00:00 2001 From: Vsevolod Tolstopyatov Date: Tue, 11 Jan 2022 17:29:21 +0300 Subject: [PATCH 2/2] Update kotlinx-coroutines-core/native/src/internal/Concurrent.kt --- kotlinx-coroutines-core/native/src/internal/Concurrent.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/kotlinx-coroutines-core/native/src/internal/Concurrent.kt b/kotlinx-coroutines-core/native/src/internal/Concurrent.kt index 9a3fd3c44e..f6e18dd5fc 100644 --- a/kotlinx-coroutines-core/native/src/internal/Concurrent.kt +++ b/kotlinx-coroutines-core/native/src/internal/Concurrent.kt @@ -32,6 +32,7 @@ internal open class SuppressSupportingThrowableImpl : Throwable() { } } +// getter instead of a property due to the bug in the initialization dependencies tracking with '-Xir-property-lazy-initialization=disabled' that Ktor uses @OptIn(ExperimentalStdlibApi::class) internal val multithreadingSupported: Boolean get() = kotlin.native.isExperimentalMM()