68

Today I was reading several articles on the Internet about fibers, coroutines and green threads, and it seems like these concepts have very much in common, but there are slight differences, especially when we talk about fibers and coroutines.

Is there a concise, correct summary of what makes them different from each other?

Update: I find the Distinguishing coroutines and fibers (N4024 C++ draft) document particularly good at differentiating between fibers and coroutines.

0

1 Answer 1

119

A Fiber is a lightweight thread that uses cooperative multitasking instead of preemptive multitasking. A running fiber must explicitly "yield" to allow another fiber to run, which makes their implementation much easier than kernel or user threads.

A Coroutine is a component that generalizes a subroutine to allow multiple entry points for suspending and resuming execution at certain locations. Unlike subroutines, coroutines can exit by calling other coroutines, which may later return to the point where they were invoked in the original coroutine.

A Green Thread is a thread that is scheduled by a virtual machine (VM) instead of natively by the underlying operating system. Green threads emulate multithreaded environments without relying on any native OS capabilities, and they are managed in user space instead of kernel space, enabling them to work in environments that do not have native thread support.

7
  • 13
    I can only say for myself - this answer is very valuable to me. I share opinion with Robert on this.
    – DejanLekic
    Aug 22, 2014 at 15:16
  • 1
    Note, coroutines and fibers could be considered quite closely related -- possibly even the same thing. If one wanted coroutines, they can be implemented via fibers with very little effort, and vice versa.
    – cHao
    Aug 23, 2014 at 0:36
  • 22
    Doesn't explain how they are different. All these definitions seem rather equivalent.
    – hasen
    Dec 6, 2017 at 4:22
  • 3
    There is no need to get into VMs for green threads. Jun 10, 2019 at 15:47
  • 1
    @gstackoverflow: Java threads are OS threads. The JVM schedules them through the OS. Jun 28, 2019 at 14:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.