answersLogoWhite

0

Semaphores and monitors are both synchronization mechanisms used in concurrent programming, but they have some key differences.

Semaphores are simple integer variables that are used to control access to shared resources by multiple threads. They can be used to signal when a resource is available or to block threads until a resource becomes available. Semaphores are low-level and require explicit management by the programmer.

Monitors, on the other hand, are higher-level constructs that encapsulate both data and synchronization operations within a single object. Monitors provide a more structured way to manage shared resources by allowing only one thread to access the resource at a time. Monitors also provide mechanisms for condition variables, which allow threads to wait for specific conditions to be met before proceeding.

In summary, semaphores are lower-level synchronization primitives that require explicit management, while monitors are higher-level constructs that provide a more structured and convenient way to manage shared resources in concurrent programming.

User Avatar

AnswerBot

4mo ago

What else can I help you with?

Related Questions

What is Monitors and Semaphores?

a semaphore is a stoplight and or traffic signal.


What is weak semaphore and strong semaphore?

strong semaphores specify the order in which processes are removed from the queue, which guarantees avoiding starvation. Weak semaphores do not specify the order in which processes are removed from the queue.


How does the signal operation associated with monitors differ from the corresponding operation defined for semaphores?

The signal() operations associated with monitors is not persistent in the following sense: if a signal is performed and if there are no waiting threads, then the signal is simply ignored and the system does not remember the fact that the signal took place. If a subsequent wait operation is performed, then the corresponding thread simply blocks. In semaphores, on the other hand, every signal results in a corresponding increment of the semaphore value even if there are no waiting threads. A future wait operation would immediately succeed because of the earlier increment.


What has the author Louisa G Bianchin written?

Louisa G. Bianchin has written: 'Differences between teachers and monitors concerning the role of the monitor'


What are disadvantages of semaphore?

In semaphores there is no spinning, hence no waste of resources due to no busy waiting. That is because threads intending to access the critical section are queued. And could access the priority section when the are de-queued, which is done by the semaphore implementation itself, hence, unnecessary CPU time is not spent on checking if a condition is satisfied to allow the thread to access the critical section.Semaphores permit more than one thread to access the critical section, in contrast to alternative solution of synchronization like monitors, which follow the mutual exclusion principle strictly. Hence, semaphores allow flexible resource management.Finally, semaphores are machine independent, as they are implemented in the machine independent code of the microkernel services.DisadvantagesProblem 1: Programming using Semaphores makes life harder as utmost care must be taken to ensure Ps and Vs are inserted correspondingly and in the correct order so that mutual exclusion and deadlocks are prevented. In addition, it is difficult to produce a structured layout for a program as the Ps and Vs are scattered all over the place. So the modularity is lost. Semaphores are quite impractical when it comes to large scale use.Problem 2: Semaphores involve a queue in its implementation. For a FIFO queue, there is a high probability for a priority inversion to take place wherein a high priority process which came a bit later might just have to wait when a low priority one is in the critical section. For example, consider a case when a new smoker joins and is desperate to smoke. What if the agent who handles the distribution of the ingredients follows a FIFO queue (wherein the desperate smoker is last according to FIFO) and chooses the ingredients apt for another smoker who would rather wait some more time for a next puff?


Type of monitors?

There are: CRT monitors (those fat monitors) and LCD monitors (flat screens)


What is the similarity between semaphore and monitor?

The wait and signal operations on condition variables in a monitor are similar to P and Voperations on counting semaphores. A wait statement can block a process's execution, while a signal statement can cause another process to be unblocked. However, there are some differences between them. When a process executes a Poperation, it does not necessarily block that process because the counting semaphore may be greater than zero. In contrast, when a wait statement is executed, it always blocks the process. When a task executes a V operation on a semaphore, it either unblocks a task waiting on that semaphore or increments the semaphore counter if there is no task to unlock. On the other hand, if a process executes a signal statement when there is no other process to unblock, there is no effect on the condition variable. Another difference between semaphores and monitors is that users awaken by a V operation can resume execution without delay. Contrarily, users awaken by a signaloperation are restarted only when the monitor is unlocked. In addition, a monitor solution is more structured than the one with semaphores because the data and procedures are encapsulated in a single module and that the mutual exclusion is provided automatically by the implementation.(excerpted from http://ei.cs.vt.edu/~cs5204/sp99/monitor.html) The wait and signal operations on condition variables in a monitor are similar to P and V operations on counting semaphores. A wait statement can block a process's execution, while a signal statement can cause another process to be unblocked. However, there are some differences between them. When a process executes a P operation, it does not necessarily block that process because the counting semaphore may be greater than zero. In contrast, when a wait statement is executed, it always blocks the process. When a task executes a V operation on a semaphore, it either unblocks a task waiting on that semaphore or increments the semaphore counter if there is no task to unlock. On the other hand, if a process executes a signal statement when there is no other process to unblock, there is no effect on the condition variable. Another difference between semaphores and monitors is that users awaken by a V operation can resume execution without delay. Contrarily, users awaken by a signal operation are restarted only when the monitor is unlocked. In addition, a monitor solution is more structured than the one with semaphores because the data and procedures are encapsulated in a single module and that the mutual exclusion is provided automatically by the implementation.(excerpted from http://ei.cs.vt.edu/~cs5204/sp99/monitor.html)


Is there gold in crt monitors?

No but there is in LCD monitors.


How does a computer monitors performance?

computer monitors


How do you write a code for a program using monitors that reads input processes it and prints onto a printer solution should involve 3 concurrent processes input process output process n use process?

You're kidding, right? Do your own comp sci homework.


How many monitors does vista support?

16 monitors !!


Are TFT monitors costlier than LCD monitors?

Yes