Synchronous Threads (1)

Synchronous threads (or ‶coroutines″) never run at the same time, and passing data from one halts the sending coroutine until the receiving one requests more data. They are like ‶threads″ excepting that they can share data because they are always synchronized:

val in : InputStream = inputFrom (new OurRunnable ());
val buffer = new javaByte [16];
loop {
  val n : integer = in.read (buffer);
  break when n <= 0;
  println ("READ (length=%d) = \"%s\""
           (n, new String (buffer, 0, n)));
}
class OurRunnable : Runnable {
  def run () : void :>
    getOut ().print ("abcdefghijklmnopqrstuvwxyz");
}
Beyond OmniMark Sam Wilmott
Slide 29 of 37 www.wilmott.ca