Green threads refers to the name of the original thread library for the programming language Java (that was released in version 1.1 and then Green threads were abandoned in version 1.3 to native threads). It was designed by The Green Team at Sun Microsystems.
In computer programming, a green thread or virtual thread is a thread that is scheduled by a runtime library or virtual machine (VM) instead of natively by the underlying operating system (OS).
Rust, in fact, has a history with green threads. A green threads runtime used to be the default paradigm for Rust code.
Green threads emulate multi-threaded environments without relying on any native OS capabilities, and they are managed in user space instead of kernel space, enabling them to work in environments that do not have native thread support.
I am well used to relying on GHC's forkIO
for portable lightweight threads when programming in Haskell.
What are equivalent libraries for C that can provide the same scalibility and ease of use?
Specifically I need C-equivalents of at least the following two functions.
forkIO :: IO () -> IO ThreadId killThread :: ThreadId -> IO ()
I assume for my application, it would be enough if threads only switched on blocking operations rather than being forcefully suspended because all threads block highly frequently for network IO and I only use the splice
system call to ask the Linux kernel to push data around between sockets.
Update
This paper has figures and tables comparing
with results favoring Protothreads. As I have not used any and there may also be other libraries, I would love to hear from anyone who has used / developed such libraries.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With