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

[DRAFT] Support sharing of coroutines across threads in Kotlin/Native #1648

Closed
wants to merge 1 commit into from

Conversation

elizarov
Copy link
Contributor

@elizarov elizarov commented Nov 7, 2019

Work in progress.

@elizarov elizarov changed the base branch from master to develop November 7, 2019 07:47
kotlin-native-sharing.md Outdated Show resolved Hide resolved
@elizarov elizarov force-pushed the native-mt branch 2 times, most recently from cc400ce to 9e975d8 Compare November 17, 2019 10:43
kotlin-native-sharing.md Outdated Show resolved Hide resolved
@elizarov
Copy link
Contributor Author

I’ve published the first development preview version of multi-threaded kotlinx.coroutines version 1.3.2-native-mt-1 for Kotlin/Native (version 1.3.60) . Make sure to study the docs before using it:
https://github.com/Kotlin/kotlinx.coroutines/blob/native-mt/kotlin-native-sharing.md

@kpgalligan
Copy link

Itr in AbstractChannel has been frozen in some of our cases and throwing immutability exceptions: https://github.com/Kotlin/kotlinx.coroutines/blob/native-mt/kotlinx-coroutines-core/common/src/channels/AbstractChannel.kt#L824. Making result atomic seems to resolve issue, although I'm new to the code and have no idea of broader implications.

@elizarov
Copy link
Contributor Author

elizarov commented Nov 22, 2019

@kpgalligan

Itr in AbstractChannel has been frozen in some of our cases and throwing immutability exceptions

Thanks! Added test with reproducer and fixed.

@elizarov
Copy link
Contributor Author

I've squashed all the changes so far into a single commit making it easier to keep it rebased on top of the develop branch and, maybe, try to integrate some of the changes separately to minimize the size of this changeset.

@kpgalligan
Copy link

kpgalligan commented Nov 30, 2019

I've been running into an issue related to state freezing and coroutines. Essentially, if freezing fails inside the "machinery" of coroutines, we can get into a weird state. Here's a basic example.

    @Test
    fun freezeFail() = runBlockingTest {
        assertFails {
            returnState()
        }
    }

    suspend fun returnState() = withContext(stateDispatcher) {
        val sd = SomeData("arst")
        sd.ensureNeverFrozen()
        sd
    }

    data class SomeData(val s: String)

stateDispatcher is a newSingleThreadContext instance. The original use case is to create a mutable state thread that we can push/pull frozen state from. That works fine, but to guard the mutable state, I call ensureNeverFrozen() on it. The idea is that if the user tries to return the mutable state, it'll throw an exception rather than freeze.

I would expect an exception to be thrown from returnState(), but according to the exception message, "Fatal exception in coroutines machinery ...", the fail happens in a place that's not expected. The test exe "hangs" and needs to be killed.

For reference, this "works" as expected...

    suspend fun returnState() = withContext(stateDispatcher) {
        val sd = SomeData("arst")
        throw IllegalStateException("just testing")
//        sd.ensureNeverFrozen()
        sd
    }

The IllegalStateException is thrown, the test passes, and the exe completes.

There is an exception written to the console

Uncaught Kotlin exception: kotlinx.coroutines.CoroutinesInternalError: Fatal exception in coroutines machinery for DispatchedContinuation[WorkerCoroutineDispatcherImpl@5340a3d8, Continuation @ $returnState$lambda-3COROUTINE$4]. Please read KDoc to 'handleFatalException' method and report this incident to maintainers
        at 0   test.kexe                           0x0000000109f1b673 kfun:kotlin.Error.<init>(kotlin.String?;kotlin.Throwable?)kotlin.Error + 115 (/Users/teamcity3/buildAgent/work/4d622a065c544371/runtime/src/main/kotlin/kotlin/Exceptions.kt:14:63)
        at 1   test.kexe                           0x000000010a024bb3 kfun:kotlinx.coroutines.CoroutinesInternalError.<init>(kotlin.String;kotlin.Throwable)kotlinx.coroutines.CoroutinesInternalError + 115 (/Users/kgalligan/temp/kotlinx.coroutines/kotlinx-coroutines-core/common/src/Exceptions.common.kt:28:77)
        at 2   test.kexe                           0x000000010a044c7d kfun:kotlinx.coroutines.DispatchedTask.handleFatalException$kotlinx-coroutines-core(kotlin.Throwable?;kotlin.Throwable?) + 925 (/Users/kgalligan/temp/kotlinx.coroutines/kotlinx-coroutines-core/common/src/internal/DispatchedTask.kt:93:22)
        at 3   test.kexe                           0x000000010a044877 kfun:kotlinx.coroutines.DispatchedTask.run() + 3559 (/Users/kgalligan/temp/kotlinx.coroutines/kotlinx-coroutines-core/common/src/internal/DispatchedTask.kt:64:13)
        at 4   test.kexe                           0x000000010a01fdef kfun:kotlinx.coroutines.EventLoopImplBase.processNextEvent()ValueType + 783 (/Users/kgalligan/temp/kotlinx.coroutines/kotlinx-coroutines-core/common/src/EventLoop.common.kt:271:20)
        at 5   test.kexe                           0x000000010a057f75 kfun:kotlinx.coroutines.runEventLoop$kotlinx-coroutines-core(kotlinx.coroutines.EventLoop?;kotlin.Function0<kotlin.Boolean>) + 869 (/Users/kgalligan/temp/kotlinx.coroutines/kotlinx-coroutines-core/native/src/Builders.kt:80:40)
        at 6   test.kexe                           0x000000010a060842 kfun:kotlinx.coroutines.WorkerCoroutineDispatcherImpl.start$lambda-0#internal + 402 (/Users/kgalligan/temp/kotlinx.coroutines/kotlinx-coroutines-core/native/src/Workers.kt:48:0)
        at 7   test.kexe                           0x000000010a060a2b kfun:kotlinx.coroutines.WorkerCoroutineDispatcherImpl.$start$lambda-0$FUNCTION_REFERENCE$15.invoke#internal + 59 (/Users/kgalligan/temp/kotlinx.coroutines/kotlinx-coroutines-core/native/src/Workers.kt:47:24)
        at 8   test.kexe                           0x000000010a060a8b kfun:kotlinx.coroutines.WorkerCoroutineDispatcherImpl.$start$lambda-0$FUNCTION_REFERENCE$15.$<bridge-UNN>invoke()#internal + 59 (/Users/kgalligan/temp/kotlinx.coroutines/kotlinx-coroutines-core/native/src/Workers.kt:47:24)
        at 9   test.kexe                           0x0000000109f4d701 WorkerLaunchpad + 177 (/Users/teamcity3/buildAgent/work/4d622a065c544371/runtime/src/main/kotlin/kotlin/native/concurrent/Internal.kt:66:54)
        at 10  test.kexe                           0x000000010a0b8bf9 _ZN6Worker19processQueueElementEb + 2569
        at 11  test.kexe                           0x000000010a0b91a6 _ZN12_GLOBAL__N_113workerRoutineEPv + 54
        at 12  libsystem_pthread.dylib             0x00007fff67fe42eb _pthread_body + 126
        at 13  libsystem_pthread.dylib             0x00007fff67fe7249 _pthread_start + 66
        at 14  libsystem_pthread.dylib             0x00007fff67fe340d thread_start + 13
Caused by: kotlin.native.concurrent.FreezingException: freezing of SomeData(s=arst) has failed, first blocker is SomeData(s=arst)
        at 0   test.kexe                           0x0000000109f21387 kfun:kotlin.Throwable.<init>(kotlin.String?)kotlin.Throwable + 87 (/Users/teamcity3/buildAgent/work/4d622a065c544371/runtime/src/main/kotlin/kotlin/Throwable.kt:22:37)
        at 1   test.kexe                           0x0000000109f1b095 kfun:kotlin.Exception.<init>(kotlin.String?)kotlin.Exception + 85 (/Users/teamcity3/buildAgent/work/4d622a065c544371/runtime/src/main/kotlin/kotlin/Exceptions.kt:23:44)
        at 2   test.kexe                           0x0000000109f1acf5 kfun:kotlin.RuntimeException.<init>(kotlin.String?)kotlin.RuntimeException + 85 (/Users/teamcity3/buildAgent/work/4d622a065c544371/runtime/src/main/kotlin/kotlin/Exceptions.kt:34:44)
        at 3   test.kexe                           0x0000000109f4c2b1 kfun:kotlin.native.concurrent.FreezingException.<init>(kotlin.Any;kotlin.Any)kotlin.native.concurrent.FreezingException + 641 (/Users/teamcity3/buildAgent/work/4d622a065c544371/runtime/src/main/kotlin/kotlin/native/concurrent/Freezing.kt:15:9)
        at 4   test.kexe                           0x0000000109f4d84e ThrowFreezingException + 222 (/Users/teamcity3/buildAgent/work/4d622a065c544371/runtime/src/main/kotlin/kotlin/native/concurrent/Internal.kt:84:15)
        at 5   test.kexe                           0x000000010a0a507b FreezeSubgraph + 2635
        at 6   test.kexe                           0x000000010a0bd03b Kotlin_Worker_freezeInternal + 27
        at 7   test.kexe                           0x0000000109f4bf9b kfun:kotlin.native.concurrent.freeze@#GENERIC.()Generic + 59 (/Users/teamcity3/buildAgent/work/4d622a065c544371/runtime/src/main/kotlin/kotlin/native/concurrent/Freezing.kt:33:5)
        at 8   test.kexe                           0x000000010a0282be kfun:kotlinx.coroutines.JobSupport.tryFinalizeSimpleState#internal + 1326 (/opt/buildAgent/work/88b0986a7186d029/atomicfu/src/nativeMain/kotlin/kotlinx/atomicfu/AtomicFU.kt:37:32)
        at 9   test.kexe                           0x000000010a032975 kfun:kotlinx.coroutines.JobSupport.tryMakeCompleting#internal + 805 (/Users/kgalligan/temp/kotlinx.coroutines/kotlinx-coroutines-core/common/src/JobSupport.kt:859:17)
        at 10  test.kexe                           0x000000010a03232e kfun:kotlinx.coroutines.JobSupport.makeCompletingOnce$kotlinx-coroutines-core(kotlin.Any?)kotlin.Any? + 590 (/Users/kgalligan/temp/kotlinx.coroutines/kotlinx-coroutines-core/common/src/JobSupport.kt:177:0)
        at 11  test.kexe                           0x000000010a00e6e4 kfun:kotlinx.coroutines.AbstractCoroutine.resumeWith(kotlin.Result<#GENERIC>) + 292 (/Users/kgalligan/temp/kotlinx.coroutines/kotlinx-coroutines-core/common/src/AbstractCoroutine.kt:111:21)
        at 12  test.kexe                           0x0000000109f416cc kfun:kotlin.coroutines.native.internal.BaseContinuationImpl.resumeWith(kotlin.Result<kotlin.Any?>) + 1420 (/Users/teamcity3/buildAgent/work/4d622a065c544371/runtime/src/main/kotlin/kotlin/coroutines/ContinuationImpl.kt:26:0)
        at 13  test.kexe                           0x000000010a044563 kfun:kotlinx.coroutines.DispatchedTask.run() + 2771 (/Users/kgalligan/temp/kotlinx.coroutines/kotlinx-coroutines-core/common/src/internal/DispatchedTask.kt:42:0)
        at 14  test.kexe                           0x000000010a01fdef kfun:kotlinx.coroutines.EventLoopImplBase.processNextEvent()ValueType + 783 (/Users/kgalligan/temp/kotlinx.coroutines/kotlinx-coroutines-core/common/src/EventLoop.common.kt:271:20)
        at 15  test.kexe                           0x000000010a057f75 kfun:kotlinx.coroutines.runEventLoop$kotlinx-coroutines-core(kotlinx.coroutines.EventLoop?;kotlin.Function0<kotlin.Boolean>) + 869 (/Users/kgalligan/temp/kotlinx.coroutines/kotlinx-coroutines-core/native/src/Builders.kt:80:40)
        at 16  test.kexe                           0x000000010a060842 kfun:kotlinx.coroutines.WorkerCoroutineDispatcherImpl.start$lambda-0#internal + 402 (/Users/kgalligan/temp/kotlinx.coroutines/kotlinx-coroutines-core/native/src/Workers.kt:48:0)
        at 17  test.kexe                           0x000000010a060a2b kfun:kotlinx.coroutines.WorkerCoroutineDispatcherImpl.$start$lambda-0$FUNCTION_REFERENCE$15.invoke#internal + 59 (/Users/kgalligan/temp/kotlinx.coroutines/kotlinx-coroutines-core/native/src/Workers.kt:47:24)
        at 18  test.kexe                           0x000000010a060a8b kfun:kotlinx.coroutines.WorkerCoroutineDispatcherImpl.$start$lambda-0$FUNCTION_REFERENCE$15.$<bridge-UNN>invoke()#internal + 59 (/Users/kgalligan/temp/kotlinx.coroutines/kotlinx-coroutines-core/native/src/Workers.kt:47:24)
        at 19  test.kexe                           0x0000000109f4d701 WorkerLaunchpad + 177 (/Users/teamcity3/buildAgent/work/4d622a065c544371/runtime/src/main/kotlin/kotlin/native/concurrent/Internal.kt:66:54)
        at 20  test.kexe                           0x000000010a0b8bf9 _ZN6Worker19processQueueElementEb + 2569
        at 21  test.kexe                           0x000000010a0b91a6 _ZN12_GLOBAL__N_113workerRoutineEPv + 54
        at 22  libsystem_pthread.dylib             0x00007fff67fe42eb _pthread_body + 126
        at 23  libsystem_pthread.dylib             0x00007fff67fe7249 _pthread_start + 66
        at 24  libsystem_pthread.dylib             0x00007fff67fe340d thread_start + 13

kotlinx.coroutines is a local build that is up to 4aacce8

@kpgalligan
Copy link

It's been a while since there's been an update. I'm not sure if this will even be relevant now, but I've run into an issue where same-thread results are unfrozen until you run an operation on another thread and return a frozen result. From then on, using the same scope, same-thread operations return frozen results.

Presumably this is due to using FreezableAtomicReference for the result.

Here's a basic example:

fun goMain() = mainScope.launch {
    val result = withContext(Dispatchers.Main){
        SomeData2("236")
    }

    println("Main isFrozen ${result.isFrozen}")
}

fun goBackground() = mainScope.launch{
    val result = withContext(Dispatchers.Default){
        SomeData2("125")
    }

    println("Default isFrozen ${result.isFrozen}")
}

data class SomeData2(val s:String)

Two methods: goMain() and goBackground(). You can call goMain() multiple times and it'll print:

Main isFrozen false

When you call goBackground() it'll print that the result is frozen. Calling goMain() again, you'll get:

Main isFrozen true

This by itself isn't a huge issue, but it made ktor unusable with the same scope. As a workaround, we created 2 scopes, and reserve 1 for ktor only. Not ideal, but workable for now. I'm assuming the FreezableAtomicReference is in Job, as the other parts of the scope are the same between multiple scopes.

Our test scope here looks like this:

class ModelScope(private val mainContext: CoroutineContext) : CoroutineScope {
    internal val job = Job()
    private val exceptionHandler = CoroutineExceptionHandler { _, throwable ->
        println("error $throwable")
        throwable.printMe()
    }

    override val coroutineContext: CoroutineContext
        get() = mainContext + job + exceptionHandler
}

My expectation is that the same-thread behaviour would be consistent. Either always freeze or never freeze. I was surprised to have it act differently after calling another thread. Not sure how feasible that would be to implement, though.

Ktor was obviously not designed or tested to work with the MT preview version of coroutines, so it's not a huge surprise that we ran into issues.

@Thomas-Vos
Copy link
Contributor

Hi, I am experiencing some issues with the Flow combine operator. The following code will throw an exception when running on Mac OS:

package sample

import kotlinx.coroutines.*
import kotlinx.coroutines.flow.*
import kotlin.native.concurrent.*

fun main() {
    runBlocking {
        MyViewModel()
        delay(2000)
    }
}

class MyViewModel {
    val mainScope = CoroutineScope(Job() + Dispatchers.Default)

    init {
        ensureNeverFrozen()

        mainScope.launch {
            val flow = flowOf("string")
            combine(flow, flow) { a, b -> a to b }
                .collect {
                    println("this is never reached")
                }
        }
    }
}
Uncaught Kotlin exception: kotlinx.coroutines.CoroutinesInternalError: Fatal exception in coroutines machinery for DispatchedContinuation[WorkerCoroutineDispatcherImpl@53408588, Continuation @ $combineTransformInternal$lambda-0$<anonymous>_1_12COROUTINE$18]. Please read KDoc to 'handleFatalException' method and report this incident to maintainers
        at 0   KNConcurrencySamples.kexe           0x000000010c028943 kfun:kotlin.Error.<init>(kotlin.String?;kotlin.Throwable?)kotlin.Error + 115 (/Users/teamcity3/buildAgent/work/4d622a065c544371/runtime/src/main/kotlin/kotlin/Exceptions.kt:14:63)
        at 1   KNConcurrencySamples.kexe           0x000000010c08f1b3 kfun:kotlinx.coroutines.CoroutinesInternalError.<init>(kotlin.String;kotlin.Throwable)kotlinx.coroutines.CoroutinesInternalError + 115 (/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/common/src/Exceptions.common.kt:28:77)
        at 2   KNConcurrencySamples.kexe           0x000000010c0dd9bd kfun:kotlinx.coroutines.DispatchedTask.handleFatalException$kotlinx-coroutines-core(kotlin.Throwable?;kotlin.Throwable?) + 925 (/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/common/src/internal/DispatchedTask.kt:93:22)
        at 3   KNConcurrencySamples.kexe           0x000000010c0dd5b7 kfun:kotlinx.coroutines.DispatchedTask.run() + 3559 (/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/common/src/internal/DispatchedTask.kt:64:13)
        at 4   KNConcurrencySamples.kexe           0x000000010c08a3ef kfun:kotlinx.coroutines.EventLoopImplBase.processNextEvent()ValueType + 783 (/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/common/src/EventLoop.common.kt:272:20)
        at 5   KNConcurrencySamples.kexe           0x000000010c100445 kfun:kotlinx.coroutines.runEventLoop$kotlinx-coroutines-core(kotlinx.coroutines.EventLoop?;kotlin.Function0<kotlin.Boolean>) + 869 (/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/native/src/Builders.kt:80:40)
        at 6   KNConcurrencySamples.kexe           0x000000010c1078b2 kfun:kotlinx.coroutines.WorkerCoroutineDispatcherImpl.start$lambda-0#internal + 402 (/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/native/src/Workers.kt:48:0)
        at 7   KNConcurrencySamples.kexe           0x000000010c107a9b kfun:kotlinx.coroutines.WorkerCoroutineDispatcherImpl.$start$lambda-0$FUNCTION_REFERENCE$11.invoke#internal + 59 (/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/native/src/Workers.kt:47:24)
        at 8   KNConcurrencySamples.kexe           0x000000010c107afb kfun:kotlinx.coroutines.WorkerCoroutineDispatcherImpl.$start$lambda-0$FUNCTION_REFERENCE$11.$<bridge-UNN>invoke()#internal + 59 (/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/native/src/Workers.kt:47:24)
        at 9   KNConcurrencySamples.kexe           0x000000010c054211 WorkerLaunchpad + 177 (/Users/teamcity3/buildAgent/work/4d622a065c544371/runtime/src/main/kotlin/kotlin/native/concurrent/Internal.kt:66:54)
        at 10  KNConcurrencySamples.kexe           0x000000010c158e59 _ZN6Worker19processQueueElementEb + 2569
        at 11  KNConcurrencySamples.kexe           0x000000010c159406 _ZN12_GLOBAL__N_113workerRoutineEPv + 54
        at 12  libsystem_pthread.dylib             0x00007fff73934e65 _pthread_start + 148
        at 13  libsystem_pthread.dylib             0x00007fff7393083b thread_start + 15
Caused by: kotlin.native.concurrent.InvalidMutabilityException: mutation attempt of frozen kotlinx.coroutines.flow.internal.$combineTransformInternal$lambda-0COROUTINE$21@53501d98
        at 0   KNConcurrencySamples.kexe           0x000000010c02e577 kfun:kotlin.Throwable.<init>(kotlin.String?)kotlin.Throwable + 87 (/Users/teamcity3/buildAgent/work/4d622a065c544371/runtime/src/main/kotlin/kotlin/Throwable.kt:22:37)
        at 1   KNConcurrencySamples.kexe           0x000000010c0283c5 kfun:kotlin.Exception.<init>(kotlin.String?)kotlin.Exception + 85 (/Users/teamcity3/buildAgent/work/4d622a065c544371/runtime/src/main/kotlin/kotlin/Exceptions.kt:23:44)
        at 2   KNConcurrencySamples.kexe           0x000000010c028025 kfun:kotlin.RuntimeException.<init>(kotlin.String?)kotlin.RuntimeException + 85 (/Users/teamcity3/buildAgent/work/4d622a065c544371/runtime/src/main/kotlin/kotlin/Exceptions.kt:34:44)
        at 3   KNConcurrencySamples.kexe           0x000000010c052e85 kfun:kotlin.native.concurrent.InvalidMutabilityException.<init>(kotlin.String)kotlin.native.concurrent.InvalidMutabilityException + 85 (/Users/teamcity3/buildAgent/work/4d622a065c544371/runtime/src/main/kotlin/kotlin/native/concurrent/Freezing.kt:22:60)
        at 4   KNConcurrencySamples.kexe           0x000000010c054648 ThrowInvalidMutabilityException + 680 (/Users/teamcity3/buildAgent/work/4d622a065c544371/runtime/src/main/kotlin/kotlin/native/concurrent/Internal.kt:89:11)
        at 5   KNConcurrencySamples.kexe           0x000000010c151498 MutationCheck + 104
        at 6   KNConcurrencySamples.kexe           0x000000010c04cb70 kfun:kotlin.coroutines.native.internal.ContinuationImpl.<set-intercepted>#internal + 96 (/Users/teamcity3/buildAgent/work/4d622a065c544371/runtime/src/main/kotlin/kotlin/coroutines/ContinuationImpl.kt:98:13)
        at 7   KNConcurrencySamples.kexe           0x000000010c04d17c kfun:kotlin.coroutines.native.internal.ContinuationImpl.releaseIntercepted() + 428 (/Users/teamcity3/buildAgent/work/4d622a065c544371/runtime/src/main/kotlin/kotlin/coroutines/ContinuationImpl.kt:110:9)
        at 8   KNConcurrencySamples.kexe           0x000000010c04d926 kfun:kotlin.coroutines.native.internal.BaseContinuationImpl.resumeWith(kotlin.Result<kotlin.Any?>) + 1222 (/Users/teamcity3/buildAgent/work/4d622a065c544371/runtime/src/main/kotlin/kotlin/coroutines/ContinuationImpl.kt:26:0)
        at 9   KNConcurrencySamples.kexe           0x000000010c0ebc3f kfun:kotlinx.coroutines.selects.SelectBuilderImpl.resumeWith(kotlin.Result<#GENERIC>) + 2159 (/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/common/src/internal/DispatchedTask.kt:165:5)
        at 10  KNConcurrencySamples.kexe           0x000000010c04d9ec kfun:kotlin.coroutines.native.internal.BaseContinuationImpl.resumeWith(kotlin.Result<kotlin.Any?>) + 1420 (/Users/teamcity3/buildAgent/work/4d622a065c544371/runtime/src/main/kotlin/kotlin/coroutines/ContinuationImpl.kt:26:0)
        at 11  KNConcurrencySamples.kexe           0x000000010c0dd2a3 kfun:kotlinx.coroutines.DispatchedTask.run() + 2771 (/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/common/src/internal/DispatchedTask.kt:42:0)
        at 12  KNConcurrencySamples.kexe           0x000000010c08a3ef kfun:kotlinx.coroutines.EventLoopImplBase.processNextEvent()ValueType + 783 (/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/common/src/EventLoop.common.kt:272:20)
        at 13  KNConcurrencySamples.kexe           0x000000010c100445 kfun:kotlinx.coroutines.runEventLoop$kotlinx-coroutines-core(kotlinx.coroutines.EventLoop?;kotlin.Function0<kotlin.Boolean>) + 869 (/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/native/src/Builders.kt:80:40)
        at 14  KNConcurrencySamples.kexe           0x000000010c1078b2 kfun:kotlinx.coroutines.WorkerCoroutineDispatcherImpl.start$lambda-0#internal + 402 (/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/native/src/Workers.kt:48:0)
        at 15  KNConcurrencySamples.kexe           0x000000010c107a9b kfun:kotlinx.coroutines.WorkerCoroutineDispatcherImpl.$start$lambda-0$FUNCTION_REFERENCE$11.invoke#internal + 59 (/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/native/src/Workers.kt:47:24)
        at 16  KNConcurrencySamples.kexe           0x000000010c107afb kfun:kotlinx.coroutines.WorkerCoroutineDispatcherImpl.$start$lambda-0$FUNCTION_REFERENCE$11.$<bridge-UNN>invoke()#internal + 59 (/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/native/src/Workers.kt:47:24)
        at 17  KNConcurrencySamples.kexe           0x000000010c054211 WorkerLaunchpad + 177 (/Users/teamcity3/buildAgent/work/4d622a065c544371/runtime/src/main/kotlin/kotlin/native/concurrent/Internal.kt:66:54)
        at 18  KNConcurrencySamples.kexe           0x000000010c158e59 _ZN6Worker19processQueueElementEb + 2569
        at 19  KNConcurrencySamples.kexe           0x000000010c159406 _ZN12_GLOBAL__N_113workerRoutineEPv + 54
        at 20  libsystem_pthread.dylib             0x00007fff73934e65 _pthread_start + 148
        at 21  libsystem_pthread.dylib             0x00007fff7393083b thread_start + 15

I don't think this is supposed to happen. It only happens with the combine operator for me, so I think that is the issue. The sample crashes for me with version 1.3.3-native-mt.

@wuseal
Copy link

wuseal commented Feb 5, 2020

Hi, I want to know when could this feature been release, any plan for this?

@elizarov elizarov force-pushed the native-mt branch 2 times, most recently from 6ef8a5e to 2ae053d Compare March 4, 2020 11:32
@qwwdfsad qwwdfsad force-pushed the develop branch 3 times, most recently from 4a49830 to aff8202 Compare March 10, 2020 17:27
@kharchenkovitaliypt
Copy link

Please publish 1.3.4-native-mt

@elizarov
Copy link
Contributor Author

Please publish 1.3.4-native-mt

Sorry, we cannot. It cannot be built with Kotlin 1.3.70. The plan is to publish it when 1.3.71 is out.

@qwwdfsad qwwdfsad force-pushed the native-mt branch 3 times, most recently from 46f7abd to 9d03705 Compare May 14, 2021 15:23
@qwwdfsad qwwdfsad force-pushed the native-mt branch 4 times, most recently from 8df9c27 to 48cf2cf Compare July 12, 2021 13:32
@qwwdfsad qwwdfsad force-pushed the native-mt branch 3 times, most recently from e0f92a6 to 386640c Compare September 2, 2021 11:27
@qwwdfsad qwwdfsad force-pushed the native-mt branch 7 times, most recently from 58811d5 to 17e0fc9 Compare December 16, 2021 16:08
@Thomas-Vos
Copy link
Contributor

The latest Ktor release at this time is built with 1.5.2-native-mt. However, I would like to use Coroutines 1.6.0-native-mt in my project (which has Ktor as a dependency), but it does not seem to compatible. Is that supposed to be the case? I get the following error:

> Task :common:root:linkCommonDebugFrameworkIosArm64
e: Module "io.ktor:ktor-network" has a reference to symbol kotlinx.coroutines/SingleThreadDispatcher|null[0]. Neither the module itself nor its dependencies contain such declaration.

This could happen if the required dependency is missing in the project. Or if there is a dependency of "io.ktor:ktor-network" that has a different version in the project than the version that "io.ktor:ktor-network" was initially compiled with. Please check that the project configuration is correct and has consistent versions of all required dependencies.

See for more information: https://kotlinlang.slack.com/archives/C0A974TJ9/p1640280717189900

@dkhalanskyjb
Copy link
Collaborator

@Thomas-Vos
Copy link
Contributor

@dkhalanskyjb thanks, but that would not work for me. I am using Ktor 2.0.0 specific features (UDP sockets) so I am stuck with the 2.0.0 releases.

@qwwdfsad qwwdfsad force-pushed the native-mt branch 5 times, most recently from 1ee4f5d to ce57d59 Compare April 5, 2022 12:31
* Provides newSingleThreadedContext.
* Provides Dispatchers.Main on iOS, Dispatchers.Default everywhere.
* Coroutine references (Job), all kinds of channels and StateFlow are shareable across workers.
* Each individual coroutine is confined to a single worker.
* Update Dispatchers docs to account for native-mt changes.
* Multithreaded support in select expression.
* Fix ObjC autorelease object leaks with native-mt dispatchers (#2477)

Additional fixes:
* Fixed broadcast builder with different thread
* Fixed adding a child to a frozen parent job

Fixes #462
Fixes #470
Fixes #765
Fixes #1645
Fixes #1751
Fixes #1828
Fixes #1831
Fixes #1764
Fixes #2064
Fixes #2025
Fixes #2226
Fixes #2138
Fixes #2263
Fixes #2322
Fixes #2283
Fixes #2688
Fixes #2398
Fixes #3136
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.