3 ms·
>if a continuation gets into an infinite loop, we can ask it to preempt itself, and forcefully remove it from the CPU. This is interesting, any idea of how the
by mapcars 7y ago
>if a continuation gets into an infinite loop, we can ask it to preempt itself, and forcefully remove it from the CPU.
This is interesting, any idea of how they can do it?
- repolfx 7y agoThat's easy. All Java threads regularly pass through "safe points" where the runtime can choose to suspend them. Think about garbage collection - the runtime must be able to reliably and regularly pause threads so their stacks can be scanned. Whether interpreted or JIT compiled, there are ways to queue a piece of code 'into' a thread that's currently running and a short time later that code will execute. Safe points are used for many different things in HotSpot. So whilst I haven't looked at the code, presumably continuations are pre-empted by forcing the host thread to a safepoint and then unmounting it. Note that forced pre-emption + a scheduler + a userspace notion of a thread gives you the tiniest core of an operating system. The next big leap in operating system design is certainly language-generic virtual machines fused with the basics of an OS.