Sync
This commit is contained in:
parent
6f050a029e
commit
776bba907c
3887 changed files with 59894 additions and 7280 deletions
|
|
@ -1,28 +1,19 @@
|
|||
procedure main()
|
||||
local prod, cons
|
||||
prod := create producer("input.txt")
|
||||
cons := create consumer(prod)
|
||||
@cons
|
||||
procedure main(A)
|
||||
fName := A[1]|"index.txt"
|
||||
p := thread produce(fName)
|
||||
c := thread consume(p)
|
||||
every wait(p | c)
|
||||
end
|
||||
|
||||
procedure producer(fname)
|
||||
local f
|
||||
f := open(fname) | stop("Unable to open ", fname)
|
||||
# send what we read [read(f)] to the consumer (&source)
|
||||
while read(f) @ &source
|
||||
# send it 'null' which we use as a signal to request count
|
||||
write("count = ", &null @ &source)
|
||||
procedure produce(fName)
|
||||
every !open(fName)@>> # drop messages in p's outbox (blocking whenever box is full)
|
||||
@>> # Signal consumer that p is done
|
||||
write("count is ",<<@) # block until message in p's inbox
|
||||
end
|
||||
|
||||
procedure consumer(p)
|
||||
local value, i
|
||||
i := 1
|
||||
value := @p
|
||||
while \value do {
|
||||
write("=> ",value)
|
||||
value := @ &source
|
||||
i := i + 1
|
||||
}
|
||||
# send producer our count
|
||||
i @ &source
|
||||
procedure consume(p)
|
||||
i := 0
|
||||
while write(\<<@p) do (i+:=1) # loop until empty message in p's outbox
|
||||
# (blocking until each message arrives)
|
||||
i@>>p # put row count into p's inbox
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue