Explain Monitor

Q1. What is a Monitor?

Ans. Suppose that the two downs in the producer’s code were reversed in order, so mutex was decremented before empty instead of after it. If the buffer were completely full, the producer would block, with mutex set to 0. Consequently, the next time the consumer tried to access the buffer, it would do a down on mutex, now 0, and block too. Both processes would stay blocked forever and no more work would ever be done. This unfortunate situation is called as a deadlock.

A monitor is a collection of procedures, variables, and data structures that are all grouped together in a special kind of module or package. Processes may call the procedure in a monitor whenever they want to, but they cannot directly access the monitor’s internal data structures from procedures declared outside the monitor.

Following is an example to illustrate monitor written in an imaginary language, Pidgin Pascal.

Monitor Example:

integer i;

condition c;

 

procedure producer();

.

.

.

end;

 

procedure consumer();

.

end;

end monitor;

Leave a Reply

Your email address will not be published. Required fields are marked *

54 Views
%d bloggers like this: