Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Монитор представляет собой коллекцию переменных и структур данных, сгруппированных вместе в специальную разновидность модуля или пакета процедур
- monitor ProducerConsumer
- condition full, empty;
- integer count;
- procedure insert(item: integer);
- begin
- if count = N then wait(full);
- insert item(item);
- count := count + 1;
- if count =1 then signal(empty)
- end;
- function remove : integer;
- begin
- if count =0 then wait(empty);
- remove = remove item;
- count := count − 1;
- if count = N− 1 then signal(full)
- end;
- count := 0;
- end monitor;
- procedure producer;
- begin
- while true do
- begin
- item = produce item;
- ProducerConsumer.insert(item)
- End
- end;
- procedure consumer;
- begin
- while true do
- begin
- item = ProducerConsumer.remove;
- consume item(item)
- end
- end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement