Compare the Difference Between Similar Terms

Difference Between

Home / Technology / IT / Programming /Difference Between Semaphore and Monitor

Difference Between Semaphore and Monitor

2011年6月12日Posted byIndika

Semaphore vs Monitor

Semaphore is a data structure that is used to make sure that multiple processes do not access a common resource or a critical section at the same time, in parallel programming environments. Semaphores are used to avoid dead locks and race conditions. Monitor is a programming language construct that is also used to avoid multiple processes accessing a common resource at the same time therefore guarantees mutual exclusion. Monitors use conditional variables to achieve this task.

What is a Semaphore?

Semaphore is a data structure that is used to provide mutual exclusion to critical sections. Semaphores mainly support two operations called wait (historically known as P) and signal (historically known as V). The wait operation blocks a process until the semaphore is open and the signal operation allows another process (thread) to enter. Each semaphore is associated with a queue of waiting processes. When the wait operation is called by a thread, if the semaphore is open, the thread can continue. If the semaphore is closed when the wait operation is called by a thread, the thread is blocked and it has to wait in the queue. The signal operation opens a semaphore and if there is a thread already waiting in the queue, that process is allowed to proceed and if there are no threads waiting in the queue the signal is remembered for the next threads. There are two types of semaphores called mutex semaphores and counting semaphores. Mutex semaphores allow a single access to a resource and counting semaphores allow multiple threads to access a resource (which has several units available).

What is a Monitor?

A monitor is a programming language construct that is used to control access to shared data. Monitors encapsulate shared data structures, procedures (that operate on shared data structures) and synchronization between concurrent procedure invocations. A monitor makes sure that its data is not faced with unstructured accesses and guarantees that treads (which access monitor’s data through its procedures) interact in a legitimate manner. A monitor guarantees mutual exclusion by allowing only one thread to execute any monitor procedure at a given time. If another thread tries to invoke a method in the monitor, while a thread is already executing a procedure in the monitor, then the second procedure is blocked and it has to wait in the queue. There are two types of monitors named Hoare monitors and Mesa monitors. They mainly differ in their scheduling semantics.

What is the difference between Semaphore and Monitor?

尽管信号量和监视器都用于在平行编程环境中实现相互排除,但它们在实现此任务的技术方面有所不同。在监视器中,用于实现相互排除的代码位于一个位置并且更结构化,而信号量的代码则以等待和信号函数调用分布。另外,实施信号量时犯错很容易,而在实施监视器时几乎没有机会犯错误。此外,监视器使用条件变量,而信号量则不使用。

Related posts:

Difference Between Dictionary and Hashtable Difference between Java and J2EE Difference Between Integer and Pointer Difference Between Implements and Extends Difference Between Source Program and Object ProgramDifference Between Source Program and Object Program

Filed Under:ProgrammingTagged With:counting semaphores,Hoare monitors,Mesa monitors,Monitor,mutex semaphores,Semaphore,signal operation,等待操作

About the Author:Indika

Indika, BSc.Eng, MSECE Computer Engineering, PhD. Computer Science, is an Assistant Professor and has research interests in the areas of Bioinformatics, Computational Biology, and Biomedical Natural Language Processing.

Comments

  1. 艾达says

    December 21, 2018 at 3:15 am

    Well described

    回复

发表评论Cancel reply

Your email address will not be published.Required fields are marked*

Request Article

Featured Posts

Difference Between Coronavirus and Cold Symptoms

Difference Between Coronavirus and Cold Symptoms

Difference Between Coronavirus and SARS

Difference Between Coronavirus and SARS

Difference Between Coronavirus and Influenza

Difference Between Coronavirus and Influenza

Difference Between Coronavirus and Covid 19

Difference Between Coronavirus and Covid 19

You May Like

Difference Between Cyclobutane and Cyclopropane

Difference Between Cyclobutane and Cyclopropane

Difference Between Endurance and Perseverance

Difference Between Endurance and Perseverance

血红蛋白和血细胞比容的区别

浓酸和浓酸之间的差异

浓酸和浓酸之间的差异

Difference Between Cleavage and Fracture

Difference Between Cleavage and Fracture

Latest Posts

  • What is the Difference Between Vermicompost and Compost
  • What is the Difference Between Depression and Schizophrenia
  • 分子几何和电子几何形状有什么区别
  • What is the Difference Between 2B and HB Pencil
  • What is the Difference Between Hypothalamus and Pituitary Gland
  • What is the Difference Between Graphite and Lead
  • Home
  • Vacancies
  • About
  • Request Article
  • 联系我们

Copyright © 2010-2018Difference Between. All rights reserved.Terms of Use和隐私政策:Legal.