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-comm3.sml < prev    next >
Encoding:
Text File  |  1991-06-22  |  837 b   |  28 lines

  1. (* ex-simple-comm3.sml
  2.  *
  3.  * COPYRIGHT (c) 1990 by John H. Reppy.  See COPYRIGHT file for details.
  4.  *
  5.  * A simple example of process comunication with guards and abort functions.
  6.  *)
  7.  
  8. (* BEGIN EXAMPLE *)
  9. fun simple_comm3 () = 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.     select [
  17.           guard (fn () => (
  18.             pr "guard-0.1\n";
  19.             wrapAbort (wrap (receive ch1, fn _ => pr "bye-0.1\n"),
  20.               fn () => pr "abort-0.1\n"))),
  21.           guard (fn () => (
  22.             pr "guard-0.2\n";
  23.             wrapAbort (wrap (receive ch2, fn _ => pr "bye-0.2\n"),
  24.               fn () => pr "abort-0.2\n")))
  25.         ]
  26.       end
  27. (* END EXAMPLE *)
  28.