Fibers, what for?
chmike via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Jun 13 00:03:36 PDT 2016
On Monday, 13 June 2016 at 00:57:11 UTC, Alex Parrill wrote:
> This is misleading. Any sort of cooperative system needs
> synchronization when two or more tasks try to access the same
> data, whether those "tasks" are OS threads, fibers, different
> machines on a network, etc.
That is true. Sorry. What I meant is that with fibers the yield
is performed in well defined locations it could be in blocking
calls like read() or write() or when yield is called.
For this reason it is simpler to synchronize access to shared
ressources with fibers than with threads. It's thus POSSIBLE to
write code that doesn't need synchronization even when shared
ressources are used.
Note also that the synchronization mechanism can be much simpler
and efficient than the one needed with threads.
With threads you MUST allways synchronize access to shared
ressources and protect critical sections of your code, or use
specially crafted none blocking data structures using atomic
operations.
More information about the Digitalmars-d-learn
mailing list