184 views
3 3 votes

Suppose $\texttt{x}$ is a condition variable inside a monitor.

What happens when a process executes:

$\texttt{x.wait()}$

  1. Mutual exclusion is established on variable $\texttt{x}$
     
  2. One process blocked on $\texttt{x}$ is awakened
     
  3. The value of $\texttt{x}$ is tested to determine whether the process should block
     
  4. The executing process is blocked and inserted into the waiting queue associated with $\texttt{x}$

2 Answers

1 1 vote

A condition variable is not an ordinary Boolean or integer whose value is inspected.

When a process executes:

$\texttt{x.wait()}$

the process cannot continue.

It is:

  1. blocked,

  2. placed in the queue associated with condition variable $\texttt{x}$,

  3. and monitor ownership becomes available so another process can enter.

A $\texttt{signal()}$ operation is used to wake a waiting process.

Therefore:

  1. False
     
  2. False, this describes $\texttt{signal()}$
     
  3. False
     
  4. True
     

Answer: D

1 1 vote

A monitor is a high-level programming language synchronization construct (implemented at the compiler level) designed to make concurrent programming easier and less error-prone than using low-level tools like semaphores.

The defining characteristic of a monitor is automatic mutual exclusion. The compiler guarantees that only one process/thread can be active inside the monitor at any single instant. If a process attempts to call a monitor procedure while another process is already executing inside it, the new process is automatically blocked and placed in the entry queue to wait its turn.

1. Why do we need Condition Variables?

While automatic mutual exclusion is great, it is not enough on its own. Sometimes a process enters the monitor but finds that a required condition is not met (for example, a producer process enters the monitor but finds the shared buffer is full).

If the process just sits there and spins waiting for the buffer to empty, it will block the entire monitor. Because no other process can enter the monitor, a consumer process could never enter to empty the buffer, resulting in a permanent deadlock.

To solve this, monitors introduce condition variables (like x and y). They allow a process to safely suspend itself and release the monitor lock so that another process can enter.


2. How x.wait() and x.signal() Work

Unlike semaphores, condition variables do not have an integer value. They do not count or save signals. There are only two operations you can perform on a condition variable:

  • x.wait():
    • Action: The executing process is immediately and unconditionally suspended (blocked).
    • Queueing: The process is placed into a waiting queue specifically associated with the condition variable x.
    • Releasing Lock: Crucially, this operation atomically releases the monitor’s mutual-exclusion lock. This allows other waiting processes (like a consumer) to enter the monitor and change the state.
  • x.signal():
    • Action: This resumes exactly one process that was blocked in the queue for condition variable x.
    • No Memory: If no processes are currently waiting in the queue for x, calling x.signal() does absolutely nothing (the signal is lost forever). (This is a major difference from semaphores, where signaling always increments a counter, keeping a memory of the signal for future waits).
Answer:
Position:
Show:

Related questions

6 6 votes
2 2 answers
243
243 views
GO Classes asked Aug 31
243 views
Which of the following data structures can be used by a file system to manage free disk blocks?Bitmap Inode Free-block linked list File Allocation Table, FAT I and II onl...
4 4 votes
1 1 answer
168
168 views
GO Classes asked Aug 31
168 views
A segmentation-based memory-management system maintains a shared segment table.Processes $P_1$ and $P_2$ both share segment $S$.Which of the following statements is incor...
4 4 votes
1 1 answer
175
175 views
GO Classes asked Aug 31
175 views
Three processes $P_1$, $P_2$, and $P_3$ are scheduled using Round Robin.Assume:Each process has one kernel threadTime quantum $=\text{10 ms}$Context switch time $=\text{1...
2 2 votes
1 1 answer
122
122 views
GO Classes asked Aug 31
122 views
Consider the following statements about operating systems:Management of input/output operations allows peripheral devices to be shared among multiple processes. Memory ma...