57

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.

106

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.

  • 13
    I can only say for myself - this answer is very valuable to me. I share opinion with Robert on this. – DejanLekic Aug 22 '14 at 15:16
  • "Summaries of broad topics are specialty of Wikipedia, which is focused and optimized on providing this content and fostering a culture oriented on it. People willing, best capable of and experienced in providing such summaries go to Wikipedia, not to Stack Exchange.... People looking for this in search engine would be typically presented two directly competing content examples, one at SE network, another at Wikipedia... Due to reasons mentioned above, it is most likely that SE content would look inferior in comparison..." – gnat Aug 22 '14 at 15:39
  • 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 '14 at 0:36
  • 9
    Doesn't explain how they are different. All these definitions seem rather equivalent. – hasen Dec 6 '17 at 4:22
  • 1
    @gstackoverflow: Java threads are OS threads. The JVM schedules them through the OS. – Robert Harvey Jun 28 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.