about summary refs log tree commit diff stats
path: root/channel.mu
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-05-11 12:00:50 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-05-11 12:09:50 -0700
commitd2244a2f117618df541c52a1f7ec5d0fed8bcb7a (patch)
treeb0ba8cbe4cd30d176822227864a7343e3246cd99 /channel.mu
parent272e786bda374bd256759344b70f32381e021ee1 (diff)
downloadmu-d2244a2f117618df541c52a1f7ec5d0fed8bcb7a.tar.gz
1345
Diffstat (limited to 'channel.mu')
-rw-r--r--channel.mu12
1 files changed, 8 insertions, 4 deletions
diff --git a/channel.mu b/channel.mu
index a0c2b6dd..0206c2f9 100644
--- a/channel.mu
+++ b/channel.mu
@@ -1,3 +1,5 @@
+# example program: communicating between routines using channels
+
 recipe producer [
   # produce numbers 1 to 5 on a channel
   default-space:address:array:location <- new location:type, 30:literal
@@ -8,7 +10,7 @@ recipe producer [
     done?:boolean <- lesser-than n:integer, 5:literal
     break-unless done?:boolean
     # other threads might get between these prints
-    $print [produce: ], n:integer, [
+    $print [produce: ], n:integer, [ 
 ]
     chan:address:channel <- write chan:address:channel, n:integer
     n:integer <- add n:integer, 1:literal
@@ -24,7 +26,7 @@ recipe consumer [
     # read an integer from the channel
     n:integer, chan:address:channel <- read chan:address:channel
     # other threads might get between these prints
-    $print [consume: ], n:integer, [
+    $print [consume: ], n:integer, [ 
 ]
     loop
   }
@@ -34,6 +36,8 @@ recipe main [
   default-space:address:array:location <- new location:type, 30:literal
   chan:address:channel <- init-channel 3:literal
   # create two background 'routines' that communicate by a channel
-  routine1:integer <- start-running consumer:recipe, chan:address:channel
-  routine2:integer <- start-running producer:recipe, chan:address:channel
+  routine1:integer <- start-running producer:recipe, chan:address:channel
+  routine2:integer <- start-running consumer:recipe, chan:address:channel
+  wait-for-routine routine1:integer
+  wait-for-routine routine2:integer
 ]