by hackandthink · 3y ago · 0 comments
Loom seems to be a new implementation of m:n Threading for Java. How does your implementation compare?
---
Could not find references from 20 years ago, but this paper from 2014 is nice:
"Earlier M: N was considered best among all because of its performance benchmarks. Currently the Linux and Solaris have shifted from M: N to 1:1 thread model despite of the advantages of M:N. Our emphasis will be on 1:1 Model semantics for shifting. This paper gives a thorough review of operating system thread models. We have researched factors which compelled different OS platforms to shift to 1: 1 Model."
https://www.researchgate.net/publication/270217184_Thread_mo...
I believe that Loom is the first official M:N thread scheduling implementation for the JVM.
I am wondering whether to include S for socket in the syntax for scheduling.
So if you have M:N:S multiplexing you can share a socket over multiple lightweight threads which are themselves assigned to one kernel thread at a time.
My implementation is a toy compared to Loom. Loom is a serious API adaptation which causes the Thread API to work as lightweight threads, I am not sure if it handles process starvation as my M:N scheduler does.
if you put while (true) {} in a lightweight thread, I think that thread shall either be preempted by Loom if Loom implements that or it shall keep the lightweight thread assigned to that kernel thread, causing starvation of other lightweight threads.
So you might have
thread1:light1:socket1recv thread2:light2:socket1send thread1:light1:socket2recv thread1:light2:socket2send
Go's M:N Threading is a great success. I guess M:N threading is harder to implement at the OS Level.
(1) https://en.wikipedia.org/wiki/Native_POSIX_Thread_Library
Kotlin successfully introduced green threads (viz. coroutines) to the JVM world way back when. Kotlin constructs for structured concurrency are especially super nice.