def producer chan:address:shared:channel -> chan:address:shared:channel [
local-scope
load-ingredients
n:character <- copy 0
{
done?:boolean <- lesser-than n, 5
break-unless done?
$print [produce: ], n, [
]
chan:address:shared:channel <- write chan, n
n <- add n, 1
loop
}
]
def consumer chan:address:shared:channel -> chan:address:shared:channel [
local-scope
load-ingredients
{
n:character, chan:address:shared:channel <- read chan
$print [consume: ], n:character, [
]
loop
}
]
def main [
local-scope
chan:address:shared:channel <- new-channel 3
routine1:number <- start-running producer, chan
routine2:number <- start-running consumer, chan
wait-for-routine routine1
wait-for-routine routine2
]