Skip to content

Instantly share code, notes, and snippets.

@ntherning
Created October 20, 2020 06:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ntherning/a1bf85d44a5989d66677762c15587552 to your computer and use it in GitHub Desktop.
Save ntherning/a1bf85d44a5989d66677762c15587552 to your computer and use it in GitHub Desktop.
Kotlin version: 1.4.10
Coroutines version: 1.3.9-native-mt-2
When the test is run on the iOS simulator the following exception is thrown:
kotlin.native.concurrent.InvalidMutabilityException: mutation attempt of frozen kotlinx.coroutines.sync.MutexImpl.LockedQueue@788375b8
at 0 test.kexe 0x0000000104103a5d kfun:kotlin.Throwable#<init>(kotlin.String?){} + 93 (/Users/teamcity/buildAgent/work/cae0e6559deed4c4/runtime/src/main/kotlin/kotlin/Throwable.kt:23:37)
at 1 test.kexe 0x00000001040fc83b kfun:kotlin.Exception#<init>(kotlin.String?){} + 91 (/Users/teamcity/buildAgent/work/cae0e6559deed4c4/runtime/src/main/kotlin/kotlin/Exceptions.kt:23:44)
at 2 test.kexe 0x00000001040fc9fb kfun:kotlin.RuntimeException#<init>(kotlin.String?){} + 91 (/Users/teamcity/buildAgent/work/cae0e6559deed4c4/runtime/src/main/kotlin/kotlin/Exceptions.kt:34:44)
at 3 test.kexe 0x0000000104133d4b kfun:kotlin.native.concurrent.InvalidMutabilityException#<init>(kotlin.String){} + 91 (/Users/teamcity/buildAgent/work/cae0e6559deed4c4/runtime/src/main/kotlin/kotlin/native/concurrent/Freezing.kt:22:60)
at 4 test.kexe 0x0000000104135602 ThrowInvalidMutabilityException + 690 (/Users/teamcity/buildAgent/work/cae0e6559deed4c4/runtime/src/main/kotlin/kotlin/native/concurrent/Internal.kt:92:11)
at 5 test.kexe 0x000000010424a89c MutationCheck + 108
at 6 test.kexe 0x0000000104339506 kfun:kotlinx.coroutines.sync.MutexImpl.LockedQueue.<set-owner>#internal + 102 (/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/common/src/sync/Mutex.kt:350:19)
at 7 test.kexe 0x000000010433877c kfun:kotlinx.coroutines.sync.MutexImpl#unlock(kotlin.Any?){} + 3740 (/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/common/src/sync/Mutex.kt:327:29)
at 8 test.kexe 0x0000000104045a4e kfun:MutexInvalidMutabilityTest.$doTest$lambda-2$lambda-0COROUTINE$0.invokeSuspend#internal + 2206 (MutexInvalidMutabilityTest.kt:16:61)
at 9 test.kexe 0x0000000104126026 kfun:kotlin.coroutines.native.internal.BaseContinuationImpl#resumeWith(kotlin.Result<kotlin.Any?>){} + 758 (/Users/teamcity/buildAgent/work/cae0e6559deed4c4/runtime/src/main/kotlin/kotlin/coroutines/ContinuationImpl.kt:30:39)
at 10 test.kexe 0x0000000104325862 kfun:kotlinx.coroutines.DispatchedTask#run(){} + 2802 (/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/common/src/internal/DispatchedTask.kt:39:50)
at 11 test.kexe 0x00000001042d7ea6 kfun:kotlinx.coroutines.EventLoopImplBase#processNextEvent(){}kotlin.Long + 838 (/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/common/src/EventLoop.common.kt:274:18)
at 12 test.kexe 0x000000010434737f kfun:kotlinx.coroutines#runEventLoop(kotlinx.coroutines.EventLoop?;kotlin.Function0<kotlin.Boolean>){} + 911 (/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/native/src/Builders.kt:80:40)
at 13 test.kexe 0x0000000104350c37 kfun:kotlinx.coroutines.WorkerCoroutineDispatcherImpl.start$lambda-0#internal + 407 (/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/native/src/Workers.kt:49:17)
at 14 test.kexe 0x0000000104350e1e kfun:kotlinx.coroutines.WorkerCoroutineDispatcherImpl.$start$lambda-0$FUNCTION_REFERENCE$35.invoke#internal + 62 (/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/native/src/Workers.kt:47:24)
at 15 test.kexe 0x0000000104350e7e kfun:kotlinx.coroutines.WorkerCoroutineDispatcherImpl.$start$lambda-0$FUNCTION_REFERENCE$35.$<bridge-UNN>invoke(){}#internal + 62 (/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/native/src/Workers.kt:47:24)
at 16 test.kexe 0x00000001041351a7 WorkerLaunchpad + 183 (/Users/teamcity/buildAgent/work/cae0e6559deed4c4/runtime/src/main/kotlin/kotlin/native/concurrent/Internal.kt:69:54)
at 17 test.kexe 0x000000010424fe2f _ZN6Worker19processQueueElementEb + 3135
at 18 test.kexe 0x000000010424f1d6 _ZN12_GLOBAL__N_113workerRoutineEPv + 54
at 19 libsystem_pthread.dylib 0x00007fff5dcdc109 _pthread_start + 148
at 20 libsystem_pthread.dylib 0x00007fff5dcd7b8b thread_start + 15
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.newSingleThreadContext
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import kotlin.native.concurrent.ensureNeverFrozen
import kotlin.test.Test
class MutexInvalidMutabilityTest {
@Test
fun doTest() {
runBlocking(newSingleThreadContext("thread")) {
val mutex = Mutex().apply { ensureNeverFrozen() }
launch {
runCatching { mutex.withLock { delay(1000) } }.exceptionOrNull()?.printStackTrace()
}
launch {
runCatching { mutex.withLock { delay(1000) } }.exceptionOrNull()?.printStackTrace()
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment