mitchellh / libxev

libxev is a cross-platform, high-performance event loop that provides abstractions for non-blocking IO, timers, events, and more and works on Linux (io_uring or epoll), macOS (kqueue), and Wasm + WASI. Available as both a Zig and C API.
MIT License
1.87k stars 58 forks source link

Simple question #92

Open Pismice opened 4 months ago

Pismice commented 4 months ago

Hello,

First let me just say that I am sorry because it probably isnt the place to ask such questions but I didnt find any other :(

My question is: can the completions be compared to green threads or did I misunderstand something ?

Sorry for the disturbance and I wish you a nice day :smiley:

gerbyzation commented 1 month ago

Someone correct me if I'm wrong but to my understanding in general green threads are something different beyond that they both provide an async programming model. Green threads provide a concurrent programming model by essentially providing "virtual" threads to execute arbitrary units of work. The virtual threads are scheduled by the runtime on the same thread and/or additional threads (probably on less threads than the number of green/virtual threads) and run in userspace.

What this library (and the underlying APIs this abstracts such as kqueue and io_uring) provide is an asynchronous API for I/O operations and some other system calls. Syscalls are handled by the OS kernel so it's not possible to schedule your own code in this event loop. Essentially it passes a message to the OS kernel to ask it to do some work for you (read from a file for example), and it'll let you know when the requested work has been completed.