http://qs1969.pair.com?node_id=352341


in reply to Re^3: Coroutines in Perl
in thread Coroutines in Perl

By "parallel" I meant "concurrently".

And there can be no two coroutines running at the same time. There is always only one coroutine running, while all others are waiting for it to "yield" or "return".

What synchronisation problems with coroutines are you referring to?

Implementing a classic "producer-consumer" system using coroutines is straight-forward and natural. No extra mechanisms are necesary to ensure that the "consumer" is reading "valid data" or that the "producer" isn't overwitting unprecessed (by the consumer) data.

Now, one can build coroutines on top of threads, as Python does (*), but that is just an implementation detail that a programmer doesn't need to care about.

(*) I'm referring to the "Coroutine.py" library distributed with Python, which for some reason isn't mentioned as part of the "Python Standard Library".