Advertisement
Netanel671

16. Мониторы. Решение ЗПиП

Dec 27th, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. Монитор представляет собой коллекцию переменных и структур данных, сгруппированных вместе в специальную разновидность модуля или пакета процедур
  2.  
  3. monitor ProducerConsumer
  4. condition full, empty;
  5. integer count;
  6.  
  7. procedure insert(item: integer);
  8. begin
  9. if count = N then wait(full);
  10. insert item(item);
  11. count := count + 1;
  12. if count =1 then signal(empty)
  13. end;
  14.  
  15. function remove : integer;
  16. begin
  17. if count =0 then wait(empty);
  18. remove = remove item;
  19. count := count − 1;
  20. if count = N− 1 then signal(full)
  21. end;
  22.  
  23. count := 0;
  24. end monitor;
  25.  
  26. procedure producer;
  27. begin
  28. while true do
  29. begin
  30. item = produce item;
  31. ProducerConsumer.insert(item)
  32. End
  33. end;
  34.  
  35. procedure consumer;
  36. begin
  37. while true do
  38. begin
  39. item = ProducerConsumer.remove;
  40. consume item(item)
  41. end
  42. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement