3 ms·
I can't speak directly for BEAM but in most languages with built-in green threads (like BEAM's processes), one of two things happens: 1. If the call is a short
by ekimekim 6y ago
I can't speak directly for BEAM but in most languages with built-in green threads (like BEAM's processes), one of two things happens:
1. If the call is a short, syncronous operation (like stat() (well, mostly), open(), getpid()), it just calls it directly in your green thread. It occupies the entire OS-level thread while it runs.
2. For long, blocking operations (eg. nanosleep(), recv(), maybe read() depending on the nature of the fd), the runtime will translate your blocking call into a callback in the main event loop, informing your green thread when data is available to read, or your timer has expired, etc. Only once the runtime knows your operation will return immediately will it actually do the call. In the meantime this frees the OS thread to run a different green thread.