5 ms·
OS threads means context switching which means relinquishing the cpu from user space to kernel space for a time. Green threads is pure user-space. No expensive
by CraigJPerry 7y ago
OS threads means context switching which means relinquishing the cpu from user space to kernel space for a time.
Green threads is pure user-space. No expensive context switch.
- fulafel 7y agoContext switch is switching between processes or threads that a CPU core runs. In parallel computation it's well known how to avoid that: keep the thread count equal to hardware core/thread count. Green threads enable concurrency but not parallelism, so they are not applicable to accelerating computation. (core.async isn't actually green threads, except in ClojureScript, but its thread pool is more for working around blocking calls than exloiting parallelism).
- otabdeveloper4 7y ago> OS threads means context switching which means relinquishing the cpu from user space to kernel space for a time. No. The OS will switch contexts regardless of how many threads you have. Even with zero threads the OS will be context switching between processes anyways. That's just how pre-emptive multitasking works. What you're trying to say is that threads might get starved due to imperfect scheduling; but even that is wrong - you're never going to write a better scheduler than the one in the Linux kernel. I mean that seriously. If you want a deterministic scheduling routine without unpredictable delays, then just use one of the realtime schedulers provided to you by the kernel. That's what they're there for.
- CraigJPerry 7y ago> The OS will switch contexts regardless of how many threads you have With IRQs pinned (via CPU mask given to the kernel at boot time) and application process pinning, there will be no preemption of the application process. > Even with zero threads the OS will be context switching between processes anyways No, this is what pinning is explicitly for. > What you're trying to say is that threads might get starved due to imperfect scheduling No, you've misunderstood