开发者

What are (OS) monitors?

开发者 https://www.devze.com 2023-02-28 00:28 出处:网络
I\'m studying OS synchronization problems. I understand semaphores and their use in reader-writer and producer-consumer situations. 开发者_开发百科I\'m not getting the concept of monitors, though. Can

I'm studying OS synchronization problems. I understand semaphores and their use in reader-writer and producer-consumer situations. 开发者_开发百科I'm not getting the concept of monitors, though. Can someone help me understand them?


Super simple high level answer:

A semaphore counts how many are using a resource (or a pool of resources) and stops when a limit is reached. (For example, you could have a semaphore of 3 then the first 3 would be able to use the resource and then any additional would be locked out till a resource is released -- only 3 can have a lock at once.)

A monitor only allows a single lock -- by one process. When something is using it nothing else can.

A semaphore that counts to 1 is the same as a monitor.

Because a semaphore is designed to do more, a semaphore that only counted to 1 would not be efficient. (That is, when one implements a monitor it is more efficient than a semaphore which counts to 1 because a monitor has less requirements).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号