r/cpp • u/gkotorlis • 11d ago
DO NOT USE FIBERS! - I did it anyway
I'm a "pro-fiber" guy, which gets lonely fast when you search the internet for friends and mostly run into Gor Nishanov tearing them apart in P1364 ("Fibers under the magnifying glass"), or Raymond Chen writing that Win32 fibers "aren't useful for much any more."
Sometimes it feels like Microsoft just lacks the imagination for where fibers actually work. Fair point though: if you try to use fibers as a general-purpose replacement for OS threads in arbitrary code, the warnings are right. TLS issues, fixed stacks, and third-party libraries blocking worker threads are very real problems.
I built a fiber-based task scheduler anyway (the first version goes back to 2007), because when you're parallelizing sequential, CPU-bound code like an encoder or compressor on a single file, the tradeoffs are completely different. You own the task code, the number of active fibers is bounded by the work in flight, and tasks often run for just tens of microseconds before waiting on each other mid-work. In that spot, OS threads cost way too much and stackless coroutines force you to tear apart existing call chains.
I wrote up my side of the story - where the usual criticism hits the mark, where it misses, and why fibers still make sense here:
https://www.thinkmeta.com/concurrenttasks/why-fibers
Any other "pro-fiber" folks out there, or has everyone moved on to stackless coroutines / std::execution?