James Perry
1 min readJan 3, 2016

--

Hey Marco, I’m glad you’ve asked this as I just noticed I superficially mentioned it. I will write a post about fibers to explain them in more detail so thanks for the suggestion!

Fibers provides a great way to build a task system that fully utlilize the cores and an extremely fast mechanism to stop, pause/swap and start tasks. The computational cost to swapping a fiber-based task is swapping CPU stack/instruction registers — which is really optimal. Thread (context) switching is not as cheap and even just to switch one thread can cause a butterfly effect as it can cause all other N-1 threads to be switched too.

Comparing this to threads, if you want to pause a thread, you must put it to sleep invoking system calls but then a core is potentially idle and will also need two context switches — one to pause it and another wake it up. This is extremely expensive compared to Fibers — which only involves an ingenious swap of CPU registers.

--

--