home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / sml_nj / cml-098.lha / cml-0.9.8 / examples / ex-simple-comm2.sml < prev    next >
Encoding:
Text File  |  1991-06-21  |  582 b   |  22 lines

  1. (* ex-simple-comm2.sml
  2.  *
  3.  * COPYRIGHT (c) 1990 by John H. Reppy.  See COPYRIGHT file for details.
  4.  *
  5.  * A simple example of process comunication.
  6.  *)
  7.  
  8. (* BEGIN EXAMPLE *)
  9. fun simple_comm2 () = let
  10.       val ch1 = channel() and ch2 = channel()
  11.       val pr = CIO.print
  12.       in
  13.     pr "hi-0\n";
  14.     spawn (fn () => (pr "hi-1\n";  send(ch1, 17);  pr "bye-1\n"));
  15.     spawn (fn () => (pr "hi-2\n";  send(ch2, 37);  pr "bye-2\n"));
  16.     sync (choose [
  17.           wrap (receive ch1, fn _ => pr "bye-0.1\n"),
  18.           wrap (receive ch2, fn _ => pr "bye-0.2\n")
  19.         ])
  20.       end
  21. (* END EXAMPLE *)
  22.