3i Infotech Placement: Sample Questions 1 - 1 of 1245

Glide to success with Doorsteptutor material for competitive exams : get questions, notes, tests, video lectures and more- for all subjects of your exam.

Question 1

Edit

Describe in Detail

Essay▾

How is the wait/signal operations for monitor different from those for semaphores?

Explanation

Monitor

  • A programming language construct which monitors a particular location for access.
  • The program waits for access to happen and then if the value is satisfactory it processed to execute other operations.
  • The observed value is written by other thread
  • Implemented in a programing language
  • If a process provides monitor signal but no task is waiting on the condition variable than the signal is lost.
  • One process waits while the process writing the monitored location provides signal

A monitor has:

  • Shared data
  • A set of atomic operation on the data
  • A set of condition variables.

Advantages:

  • Reduces probability of error.
  • Provides low level synchronization operations.
  • Biases programmer to think about the system in a certain way.

Semaphore

  • A data structure, which provide mutual exclusion to critical sections.
  • Supports 2 operation wait and signal.
  • The semaphore does not allow another process to enter the critical location until no other process is using it.
  • The waiting process continually reads the memory location (shared semaphore) and the process exiting the critical section provides the signal by writing the semaphore.
  • Associated with a queue of waiting processes.

Two types of semaphore:

  • Counting semaphore
    • Take non-negative integer values
  • Binary semaphore:
    • Take the value 0 & 1 only.

Difference between Semaphore and Monitor

Table Shows the Difference between Semaphore and Monitor
SemaphoreMonitor
Code for semaphores is distributed as wait and signal function calls.The code that is used to achieve mutual exclusion is in a single place and is more structured.
Very easy to make mistakes when implementingA very little chance to make mistakes when implementing
Do not use condition variable.Use condition variables

Developed by: