0% found this document useful (0 votes)
12 views

Process Synchronization

The document discusses various problems related to process synchronization, including the Producer-Consumer Problem, Readers-Writers Problem, and the Dining Philosophers Problem. It poses multiple questions regarding semaphore operations, critical section access, and the effects of concurrent processes on shared variables. The document requires understanding of synchronization mechanisms and their implications on process execution and resource sharing.

Uploaded by

saurish gahlaut
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Process Synchronization

The document discusses various problems related to process synchronization, including the Producer-Consumer Problem, Readers-Writers Problem, and the Dining Philosophers Problem. It poses multiple questions regarding semaphore operations, critical section access, and the effects of concurrent processes on shared variables. The document requires understanding of synchronization mechanisms and their implications on process execution and resource sharing.

Uploaded by

saurish gahlaut
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Process Synchronization

Q. 1:

Below is the code of Producer-Consumer Problem

void Producer(){
do{
//wait until empty > 0
wait(Empty);
wait(mutex);
add()
signal(mutex);
signal(Full);
}while(TRUE);
}

void Consumer(){
do{
//wait until empty > 0
wait(full);
wait(mutex);
consume()
signal(mutex);
signal(empty);
}while(TRUE);
}

1) Can the consumer remove an item from the buffer if full () = 0?


2) Can the producer and consumer acquire the lock simultaneously?
3) What will happen if wait (full) and wait (mutex) are interchanged in Consumer ()?
4) What will happen if signal (mutex) and signal (Full) are interchanged in Producer ()?

Q. 2:

Consider a system with two processes, P1 and P2, which need to enter a critical section. They
use a binary semaphore SSS, initialized to 1, for mutual exclusion. The wait () and signal ()
operations on the semaphore take negligible time. Process P1 executes 5 times per second, and
Process P2 executes 10 times per second. Each time either process enters the critical section, it
spends 20ms in the critical section. What is the maximum time that P2 can be blocked by P1 in
entering the critical section?
Q. 3:

In a variation of the Readers-Writers problem, assume that there are 3 readers and 2 writers.
Each reader takes 2 seconds to read, and each writer takes 4 seconds to write. Writers are given
priority over readers. If at time t=0, a writer starts writing, how long will the next reader have to
wait to start reading, assuming that a writer requests access to the critical section immediately
after the first writer?

Q. 4:
Consider the two functions incr() and decr() shown below.
incr() {
wait(s);
X = X+1;
signal(s);
}
decr() {
wait(s);
X = X-1;
signal(s);
}
There are 5 threads each invoking incr() once, and 3 threads each invoking decr() once, on the
same shared variable X. The initial value of X is 10.
Suppose there are two implementations of the semaphore s, as follows:
I: s is a binary semaphore initialized to 1.
II: s is a counting semaphore initialized to 2.
Let V1, V2 be the values of X at the end of execution of all the threads with implementations I
and II, respectively.
What are the minimum possible values of V1, V2, respectively?
Q. 5:
Consider the following two threads and that update two shared variables and. Assume that
initially. Though context switching between threads can happen at any time, each statement of or
is executed atomically without interruption.

List all the possible combinations of values of a and b after both T1 and T2 finish execution.
Q. 6:

A shared variable x, initialized to zero, is operated on by four concurrent processes W, X, Y, Z


as follows. Each of the processes W and X reads x from memory, increments by one, stores it to
memory and then terminates. Each of the processes Y and Z reads x from memory, decrements
by two, stores it to memory, and then terminates. Each process before reading x invokes the P
operation (i.e. wait) on a counting semaphore S and invokes the V operation (i.e. signal) on the
semaphore S after storing x to memory. Semaphore S is initialized to two. What is the maximum
possible value of x after all process's complete execution?

Q. 7:

The following two functions P1 and P2 that share a variable B with an initial value of 2 execute
concurrently.

P1() {
C = B – 1;
B = 2 * C;
}
P2() {
D = 2 * B;
B = D - 1;
}
The number of distinct values that B can possibly take after the execution, explain briefly?

Q. 8:

Consider a non-negative counting semaphore S. the operation P(S) decrements S, and V(S)
increments S. During an execution, 20 P(S) operations and 12 V(S) operations are issued in some
order. What is the largest initial value of S for which at least one P(S) operation will remain
blocked?
Q. 9:

In a bounded buffer problem, there are 5 producer threads and 3 consumer threads. The buffer
size is 10. Producers and consumers interact with the buffer using two semaphores: empty
(initialized to 10) and full (initialized to 0). The time to produce or consume an item is 1 second.
If two producers are producing items simultaneously, how much time will pass before both of
them can place an item in the buffer, assuming the buffer was initially empty?

Q. 10:

In a variation of the Dining Philosophers problem, 5 philosophers are sitting at a table with 5
chopsticks. Each philosopher needs both chopsticks adjacent to them to eat. The time to pick up
a chopstick or put it down is negligible. The time to eat is 10 seconds. A philosopher tries to pick
up both chopsticks simultaneously to avoid deadlock. What is the minimum time required for all
philosophers to eat at least once?

You might also like