/* use only this form of commenting, but don't nest */ _monitor(bounded_buffer) op deposit(data: real), fetch() returns data: real _body(bounded_buffer) var size : int := 20; getarg(1, size) write("bounded buffer alive with", size, "slots") var buf[0:size-1]: real var front := 0, rear := 0, count := 0 _condvar(not_full); _condvar(not_empty) _proc( deposit(data) ) if count = size -> _print(not_full); _print(not_empty); _wait(not_full) fi _print(not_full); _print(not_empty) buf[rear] := data rear := (rear+1) % size count := count+1 write("there are now", count, "items in the buffer") if _empty(not_empty) -> write("no consumers are waiting") [] else -> write("consumers are waiting") fi _signal(not_empty) _proc_end _proc( fetch() returns result ) if count = 0 -> _print(not_full); _print(not_empty); _wait(not_empty) fi _print(not_full); _print(not_empty) result := buf[front] front := (front+1) % size count := count-1 write("there are now", count, "items in the buffer") if _empty(not_full) -> write("no producers are waiting") [] else -> write("producers are waiting") fi _signal(not_full) _proc_end _monitor_end