12 ms·
If you can’t break a thread out of an infinite loop, that is pure cpu and no io, then the run time is not preemptive, surely??
by diroussel 4y ago
If you can’t break a thread out of an infinite loop, that is pure cpu and no io, then the run time is not preemptive, surely??
- kaba0 4y agoAt worst the OS will preempt the thread and the JVM will likely schedule a different virt thread the next time — but in case you have multiple CPU-hungry virtual threads fighting over a single core it will suck no matter what. The performance improvement comes from doing useful work on a thread during IO waits. Nonetheless, there were discussions about some way to force preemption at certain points, not sure whether there is a decision since, but that will be the exception, not the rule.
- Yoric 4y agoStill trying to understand: what's the difference between "forc[ing] preemption" and cooperative threading?
- twic 4y agoIn cooperative threading, a thread can only be suspended when it interacts with the runtime - so when it does I/O, or yields, or uses a lock, or maybe does some reflection, or perhaps allocates, or whatever. In preemptive threading, a thread can be suspended anywhere. There is a bit of a grey area in between, where threads can be suspended outside the runtime, but not anywhere. Go had this for a while - threads could get suspended on function entry too. If you've got a thread that's in a loop in which it doesn't allocate, doesn't call other functions, doesn't interact with the runtime in any way, maybe it's just looping over huge arrays of numbers doing calculations, then a cooperative threading runtime can't suspend it, whereas a preemptive threading runtime can.
- Yoric 4y agoBut we're talking about forcing preemption, which is basically calling into the runtime, isn't it?
- twic 4y agoThe terminology you're using doesn't really make sense to me, so i don't understand what you're asking, i'm afraid. In cooperative multithreading, a thread only enters the runtime when that is part of its normal program flow. The code it's executing does I/O, or acquires a lock, or something like that. In preemptive multithreading, some mechanism can force any thread into the thread scheduler at any time.
- Yoric 4y agoIf you climb back the chain, you'll see > Nonetheless, there were discussions about some way to force preemption at certain points, not sure whether there is a decision since, but that will be the exception, not the rule. I'm trying to understand the difference between "forcing preemption" and requesting for the runtime to yield, the latter being an operation typical in cooperative multithreading.