Coroutines and multiplatform: No IO dispatcher + frozen captured data, is it possible to use blocking IO at all?

I have been trying to use Kotlin Multiplatform (for Android, Native, and JVM targets). Works well so far, except that the coroutines IO dispatcher is not available for Kotlin Multiplatform. This one is a big problem, since I have to access some system resources that do blocking IO only, like:

withContext(Dispatchers.IO) {
    myDevice.connect()
}

I probably could use the Default dispatcher instead, but that one’s thread pool is limited, so I am concerned about the possibility of a deadlock, especially on a single core machine (like an older single board computer).

Also, according to the frozen captured data section, in the call above, myDevice would be frozen. But what if for example myDevice is a Bluetooth device on Android, or some form of custom POSIX IO on Native? How far does the “freezing” go in such a case? Under the hood, IO often mutates some internal state, even when just reading (some sort of internal position counter would be one example). Freezing that would render IO impossible.

1 Like