2 ms·
You are wrong about Erlang. It's threads ("processes") are not preemptive and must explicitly yield for another thread to execute. Most of the time the VM handl
by bjourne 12y ago
You are wrong about Erlang. It's threads ("processes") are not preemptive and must explicitly yield for another thread to execute. Most of the time the VM handles it for you, every few hundred bytecode instructions it checks if another thread should run. But if you write a C extension, call sleep(10) then the Erlang VM will twiddle its thumbs for 10 seconds.
It's not a corner case -- it means any call to a C library needs to be carefully vetted so as to not cause an overly long computation or blocking because just a single one will totally ruin your concurrent experience. ALL VM:s using user mode threads/fibers suffer from that problem.
Real kernel threads doesn't have a lot of overhead and are almost always a much better choice.
- pron 12y ago> Most of the time the VM handles it for you Yes, and that's the definition of preemptive. There's nothing explicit about it if the VM handles it for you. What you're saying is that it cannot preempt kernel-thread blocking code. > Real kernel threads doesn't have a lot of overhead and are almost always a much better choice. Well, as usual, that depends. A kernel thread task-switch is 20-50us, while a fiber task-switch is a couple nanos at most; that's a 1-2 orders of magnitude difference.
- pron 12y agoSorry, I meant to say a couple hundred nanos.
- bjourne 12y agoThat's just wrong. The definition of preemptive multitasking isn't that it works most of the time. A definition that lax would mean almost any cooperative threading system would be counted as "preemptive." Also can you please find a reference that shows (Linux) kernel threads being 1-2 orders slower than user threads?