Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ClassCastException when using limitedParallelism on Kotlin/Native #3223

Closed
Thomas-Vos opened this issue Mar 26, 2022 · 0 comments
Closed

ClassCastException when using limitedParallelism on Kotlin/Native #3223

Thomas-Vos opened this issue Mar 26, 2022 · 0 comments

Comments

@Thomas-Vos
Copy link
Contributor

@Thomas-Vos Thomas-Vos commented Mar 26, 2022

My code uses Dispatchers.Default.limitedParallelism(1) on Kotlin/Native with the new memory model enabled. When launching a coroutine on this dispatcher, the following error is thrown:

Uncaught Kotlin exception: kotlin.ClassCastException: kotlinx.coroutines.internal.LimitedDispatcher cannot be cast to kotlinx.atomicfu.locks.SynchronizedObject
    at 0   common                              0x10a815d5f        kfun:kotlin.Throwable#<init>(kotlin.String?){} + 99 
    at 1   common                              0x10a80e89b        kfun:kotlin.Exception#<init>(kotlin.String?){} + 95 
    at 2   common                              0x10a80eaef        kfun:kotlin.RuntimeException#<init>(kotlin.String?){} + 95 
    at 3   common                              0x10a80f927        kfun:kotlin.ClassCastException#<init>(kotlin.String?){} + 95 
    at 4   common                              0x10a84644f        ThrowClassCastException + 655 
    at 5   common                              0x10a9f55e3        kfun:kotlinx.coroutines.internal.LimitedDispatcher.tryAllocateWorker#internal + 183 
    at 6   common                              0x10a9f535f        kfun:kotlinx.coroutines.internal.LimitedDispatcher#dispatch(kotlin.coroutines.CoroutineContext;kotlinx.coroutines.Runnable){} + 195 
    at 7   common                              0x10a9edfaf        kfun:kotlinx.coroutines.internal#resumeCancellableWith__at__kotlin.coroutines.Continuation<0:0>(kotlin.Result<0:0>;kotlin.Function1<kotlin.Throwable,kotlin.Unit>?){0§<kotlin.Any?>} + 895 
    at 8   common                              0x10a9ff0e7        kfun:kotlinx.coroutines.intrinsics#startCoroutineCancellable__at__kotlin.coroutines.SuspendFunction1<0:0,0:1>(0:0;kotlin.coroutines.Continuation<0:1>;kotlin.Function1<kotlin.Throwable,kotlin.Unit>?){0§<kotlin.Any?>;1§<kotlin.Any?>} + 411 
    at 9   common                              0x10a9ff2af        kfun:kotlinx.coroutines.intrinsics#startCoroutineCancellable$default__at__kotlin.coroutines.SuspendFunction1<0:0,0:1>(0:0;kotlin.coroutines.Continuation<0:1>;kotlin.Function1<kotlin.Throwable,kotlin.Unit>?;kotlin.Int){0§<kotlin.Any?>;1§<kotlin.Any?>} + 251 
    at 10  common                              0x10a956b8b        kfun:kotlinx.coroutines.CoroutineStart#invoke(kotlin.coroutines.SuspendFunction1<0:0,0:1>;0:0;kotlin.coroutines.Continuation<0:1>){0§<kotlin.Any?>;1§<kotlin.Any?>} + 259 
    at 11  common                              0x10a942637        kfun:kotlinx.coroutines.AbstractCoroutine#start(kotlinx.coroutines.CoroutineStart;0:0;kotlin.coroutines.SuspendFunction1<0:0,1:0>){0§<kotlin.Any?>} + 151 
    at 12  common                              0x10a946ce3        kfun:kotlinx.coroutines#launch__at__kotlinx.coroutines.CoroutineScope(kotlin.coroutines.CoroutineContext;kotlinx.coroutines.CoroutineStart;kotlin.coroutines.SuspendFunction1<kotlinx.coroutines.CoroutineScope,kotlin.Unit>){}kotlinx.coroutines.Job + 411 
    at 13  common                              0x10a946f17        kfun:kotlinx.coroutines#launch$default__at__kotlinx.coroutines.CoroutineScope(kotlin.coroutines.CoroutineContext?;kotlinx.coroutines.CoroutineStart?;kotlin.coroutines.SuspendFunction1<kotlinx.coroutines.CoroutineScope,kotlin.Unit>;kotlin.Int){}kotlinx.coroutines.Job + 427 
    at 14 ... 

I guess this function was not implemented for Kotlin/Native yet? Or is this a bug?

My project uses Coroutines version 1.6.0 and Kotlin 1.6.20-RC2.

qwwdfsad added a commit that referenced this issue Mar 29, 2022
The initial implementation predates new memory model and was never working on it

Fixes #3223
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants