World's most popular travel blog for travel bloggers.

[Solved]: Why would you use a monitor instead of a semaphore?

, , No Comments
Problem Detail: 

I am currently attending the concurrent programming course in my university and we recently started talking about the concept of a monitor. While I understand the necessity of mutual exclusion, I do not understand why I would use a monitor for that.

As I understand it, a monitor guarantees that exactly one or no process is in the critical section at all times. We can achieve exactly that with a semaphore. Furthermore we implement monitors (or at least one possibility to implement them is) with semaphores.

So why would I implement something that does exactly the same thing as a semaphore with a semaphore? What benefits do I get?

Asked By : Dennis Hein

Answered By : Dennis Hein

We finally discussed why you would use a monitor instead of a semaphore in the lecture today.

It basically comes down to this: The monitor and the semaphore are equally expressive, meaning you can find a solution for a problem with a monitor where originally a semaphore was used and vice versa.

Well, we already knew that, so why would you use a monitor instead of a semaphore?

Personal preference. Normally a desktop application would use monitors, leaving less possibilities for mistakes, but, as a trade off, having a relativly bloated structure. Semaphores on the other hand are often used in operating systems, as they are a lightweight structure, but leaving more possibilities for mistakes.

I guess we can conclude that it is a situational decision wether or not you need/want to use a monitor or a semaphore. If you build a real time system you might want to go with a semaphore, if you are building an office programm you might aswell go with a monitor.

Best Answer from StackOverflow

Question Source : http://cs.stackexchange.com/questions/43721

0 comments:

Post a Comment

Let us know your responses and feedback