寻找良好的类比/示例监视器信号量 [英] Looking for good analogy/examples for monitor verses semaphore

查看:217
本文介绍了寻找良好的类比/示例监视器信号量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

监视器应该在并发环境中解决信号量的问题。

我正在使用监视器和信号量来寻找一个好的类比。


请使用类似信息:

4个任务(TaskA,TaskB,TaskC,TaskD)

1变量 varX

A monitor is supposed to solve problems with semaphores in concurrent environments.
I'm looking for a good analogy using a monitor verses semaphore.

Please use information for the analogy:
4 tasks (TaskA, TaskB, TaskC, TaskD)
1 variable varX

每个任务都希望根据某些事件操作 varX

Each Task wants to manipulate varX based on some event.

推荐答案

假设一群患者想去看医生。

Lets say a bunch of patients wants to go see a doctor.

一个信号量实施将是他们都站在办公室门外,一旦一个病人出来,他们都试图挤压,一个人设法进入,其余的再次等待。

A semaphore implementation would be they all stand outside the door to the office, as soon as one patient comes out, they all try to squeeze through, one person manages to get in, the rest have to wait again.

监视器实现将是,所有进入的病人都被送到一个等候室,而某些类似的顺序将被确定,当一个病人完成时,另一个病人将被发送给医生。

A monitor implementation would be, all incoming patients are sent to a waiting room instead, some semblance of order will be determined and when one patient is done, another will be sent to the doctor.

基本上相同的事情,监视器只是更多的结构比信号量。

They are basically the same thing, monitors are just more structured than semaphores.

这篇关于寻找良好的类比/示例监视器信号量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆