Advertisement
Guest User

Untitled

a guest
Jul 25th, 2010
329
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. PROC box_with_maxsize(CHAN in, out) =
  2. CHAN pass_through, send_next
  3. PAR
  4. VAR head, tail, count, queue[n]:
  5. SEQ
  6. head := 0
  7. tail := 0
  8. count := 0
  9. WHILE TRUE:
  10. ALT
  11. (count < n) & in ? queue[tail] -- Input process - always ready to accept, for a sufficiently large value of n
  12. PAR -- Always accept values from sender up to queue size
  13. tail := (tail + 1) \ n
  14. count := count + 1
  15. (count > 0) & send_next ? ANY -- Pass through process
  16. SEQ -- Send on messages when reciever requests one
  17. pass_through ! queue[head]
  18. PAR
  19. head := (head + 1) \n
  20. count := count - 1
  21. WHILE TRUE -- Actual output process. Always ready to send if there's a value to send
  22. VAR x: -- In place of an output guard. Requests messages when not waiting to send a value
  23. SEQ
  24. send_next ! ANY -- Request next message from pass through process
  25. pass_through ? x -- Read value from pass_through process to send forward
  26. out ! x -- Send to out the value
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement