News for hackers. Stuff that matters.
Re:Guide to Java Virtual Threads by gpderetta on Thursday March 16, 2023 @11:09AM (#35182950)
Async is cooperative only if your executor is single threaded. If you have multiple events loop running in parallel (for example multiple c++ coroutines running in an ASIO io_service pool), it is indistinguishable from a preemptive model.

Of course some specific implementations can be single threaded only (js) or use shared nothing threads (rust), but that orthogonal with the model

Re:Guide to Java Virtual Threads by jayd16 on Thursday March 16, 2023 @02:53PM (#35186563)
Well I'm specifically talking about the single threaded executor case. (A very common case in UI programming).

If you call a plain function from an async function, you know it will not run on a different thread no matter the executor. In this Loom model, you don't know that.

You control the thread until you yield execution no matter the executor. Explicit async methods also means you get explicit sync methods. In that sense, you will not be pre-empted when code changes under you. You can write async tasks that you know will run atomically without locks because you never yielded execution.

In this implicit model, I don't believe that's the case. Because yield points can be added at any time and thus you can be pre-empted at any time, you need to use locks for atomicity (or give up and revert to using a normal Thread). I don't think its possible to interweave this implicit yielding with atomic execution in a way that's as simple as calling a sync function. Is there some other way?

Re:Guide to Java Virtual Threads by gpderetta on Thursday March 16, 2023 @03:00PM (#35186677)
Well we are discussing models in general.

If you do not want preemption disable it. For example in posix threads use sched_fifo and pin to one core.

Loom might provide similar features if needed.