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.
foreign export
of libHSrts.a ... ? (i.e. just use the GHC runtime, which is a C library, after all). That said, the GHC runtime is 50k lines of C, and usesepoll
for thread scheduling. You'd need an epoll wrapper. – PenitenceforkIO
andkillThread
as C functions? – Nata-lHSrts
. – Overpass