kevin.cianfarini
12/29/2022, 2:01 AMrunInterruptable
in Kotlin/Native (posix)? Are there technical limitation to this? I think we could do this with signals.runInterruptable
does not support native, I'm having to use a blocking call that times, and then spin needlessly with an arbitrary timeout.
For reference, this is all in the context of binding kotlin native to io_uring
. I would like to be able to do the following:
val dispatcher = newSingleThreadedContext(...)
runInterruptable(context = dispatcher) {
while (true) {
io_uring_wait_cqe(...) // blocks until kernel gives us a value.
}
}
Instead I am having to do this:
val dispatcher = newSingleThreadedContext(...)
val timeout = /* 100 milliseconds */
withContext(dispatcher) {
while (isActive) {
io_uring_wait_cqe_timeout(..., timeout) // blocks for 100ms or until kernel gives us a value.
}
}
withContext(newSingleThreadeContext(...)) {
while (isActive) {
io_uring_wait_cqe(...)
}
}
But there's a subtle bug here. If the parent coroutine scope is cancelled, and there's no new value is ever returned from io_uring_wait_cqe
, then cancelling the scope has no effect. This loop never checks the isActive
condition and it hangs forever.Dmitry Khalanskiy [JB]
12/29/2022, 12:50 PM