什么是(操作系统)监视器?
我正在研究操作系统同步问题。我了解信号量及其在读者-作者和生产者-消费者情况下的使用。不过,我不明白监视器的概念。有人可以帮助我理解它们吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
超级简单的高级答案:
信号量计算有多少人正在使用资源(或资源池),并在达到限制时停止。 (例如,您可以有一个信号量 3,那么前 3 个信号量将能够使用该资源,然后任何额外的信号量将被锁定,直到资源被释放 - 一次只有 3 个信号量可以拥有锁。)
仅限监视器允许一个进程使用一个锁。当某物正在使用它时,其他任何东西都无法使用它。
计数到 1 的信号量与监视器相同。
由于信号量被设计为可以执行更多操作,因此仅计数到 1 的信号量效率不高。 (也就是说,当实现监视器时,它比计数为 1 的信号量更有效,因为监视器的要求较少)。
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).