X-Git-Url: http://lambda.jimpryor.net/git/gitweb.cgi?p=lambda.git;a=blobdiff_plain;f=topics%2F_coroutines_and_aborts.mdwn;h=389e7d5ef47fb0ad320897b44626dd377be005ac;hp=d7c8b03ea477fed4bb0de4b8a80b3c465025e201;hb=4cd46c1664472437f701377fe1851db42ed063cf;hpb=0ee1a76d0c1fa78a8a93ea20598b56eb1496d14e diff --git a/topics/_coroutines_and_aborts.mdwn b/topics/_coroutines_and_aborts.mdwn index d7c8b03e..389e7d5e 100644 --- a/topics/_coroutines_and_aborts.mdwn +++ b/topics/_coroutines_and_aborts.mdwn @@ -1,5 +1,7 @@ [[!toc]] +## Coroutines ## + Recall [[the recent homework assignment|/exercises/assignment12]] where you solved the same-fringe problem with a `make_fringe_enumerator` function, or in the Scheme version using streams instead of zippers, with a `lazy-flatten` function. The technique illustrated in those solutions is a powerful and important one. It's an example of what's sometimes called **cooperative threading**. A "thread" is a subprogram that the main computation spawns off. Threads are called "cooperative" when the code of the main computation and the thread fixes when control passes back and forth between them. (When the code doesn't control this---for example, it's determined by the operating system or the hardware in ways that the programmer can't predict---that's called "preemptive threading.") Cooperative threads are also sometimes called *coroutines* or *generators*.