Fibers, what for?

chmike via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Jun 12 01:38:03 PDT 2016


On Sunday, 12 June 2016 at 05:11:57 UTC, Ali Çehreli wrote:

> For convenience, here's the link:
>
>   http://www.ustream.tv/recorded/86352137/highlight/699197
unfortunately iPads are not supported to view the video. :(

I see two major benefits of fibers overs threads.

Fibers don't need synchronization to access shared data. This 
removes the overhead of synchronization and simplifies 
"multitheaded" programming greatly.

The second benefit is that fibers have a much lower time cost of 
context switching. When a fiber yields the processor to another 
fiber, the switch is immediate and the other fiber can immediatly 
resume its task. With threads, you have to wait that the OS give 
the processor back to your process. This can take some time when 
there are many other threads competing for the processor. The 
performance difference is the most notable when the amount of 
work to do between switches is small.

Most popular and succesfull use for fibers is for asynchronous or 
event driven processing.






More information about the Digitalmars-d-learn mailing list