Fibers under the magnifying glass
Document Number: P1364 R0 Date: 2018-11-20
Reply-to: Gor Nishanov (gorn@microsoft.com) Audience: WG21, EWG,
SG1
Abstract
Fibers (sometimes called stackful coroutines or user mode cooperatively scheduled threads) and stackless
coroutines (compiler synthesized state machines) represent two distinct programming facilities with vast perfor-
mance and functionality differences.
This paper highlights efficiency, scalability and usability problems of fibers and reaches the conclusion that they
are not an appropriate solution for writing scalable concurrent software
Contents
1 Introduction ........................................................................................................................................................ 1
2 Threads and Fibers .............................................................................................................................................. 2
2.1 Memory Footprint ............................................................................................................................................................... 2
2.2 Context Switching overhead ............................................................................................................................................... 4
2.3 Compatibility & Scalability .................................................................................................................................................. 4
3 Case Studies ........................................................................................................................................................ 6
3.1 Fiber use on Windows ......................................................................................................................................................... 6
3.2 Solaris .................................................................................................................................................................................. 6
3.3 Linux .................................................................................................................................................................................... 7
3.4 POSIX ................................................................................................................................................................................... 7
3.5 Facebook experience .......................................................................................................................................................... 7
3.6 Programming Language survey ........................................................................................................................................... 8
4 Conclusion ........................................................................................................................................................... 8
5 Acknowledgements ............................................................................................................................................. 8
6 Bibliography ........................................................................................................................................................ 8
7 Appendix A: Stackless vs Stackful Comparison ................................................................................................. 10
1 Introduction
Coroutines is a programming concept that have been known and used since 1958. Knuth defined it as a
generalization of a subroutine: regular subroutines always start at the beginning and exit at the end, whereas
coroutines can also suspend the execution to be resumed later at the point where they were left off.
There are two common implementation strategies for coroutines: compiler-based transformation into a state
machine or implementation as an interface adapter on top of threads (regular or user-mode cooperatively
schedules ones). To disambiguate between two implementation strategies, adjective “stackless” is typically used
to indicate that a coroutine is implemented by the compiler as a state machine and “stackful” to indicate that a
coroutine is implemented on top of a user-mode cooperatively scheduled thread.