Question

Just wanted to know if mutual exclusion in monitors is at a procedure/method level or if it is at a monitor level.

I mean, in the first case, there might be 2 threads accessing the monitor, but they would be running in different procedures. In the second case, there won't be 2 threads acceding the monitor even if two different procedures are called.

Assuming it is at a monitor level, it seems much safer. However, aren't there situations in which there could be running 2 different threads in a monitor each modifying different shared variables and the monitor won't allow this to happen? If that is the case, wouldn't this lower the concurrency in the system? Or would it mean that 2 monitors should have been created instead of one?

Ok, I better finish philosophizing :) Thanks in advance

Was it helpful?

Solution

Monitor locking is completely independent of the calling method.
Had that not been the case, it would have been very difficult to prevent two different methods from executing concurrently.

If you don't want it to be, use multiple monitors.

OTHER TIPS

The mechanism of monitor operation is serializing of threads or processes. So Monitor is a skill to guarantee mutual exclusion on concurrency situation.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top