0% found this document useful (0 votes)
14 views4 pages

Unit 3 QB

Uploaded by

Jashu Jack
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views4 pages

Unit 3 QB

Uploaded by

Jashu Jack
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Department of Computer Science and Engineering

Academic Year: 2021-22

Year/Class: II / CSE A, B
Course Title: Operating Systems

Unit – 3 Process Synchronization


Short Answers
1. Define critical section
2. What is race condition?
3. What are semaphores?
4. Write about test and set instruction
5. What are the requirements from any solution to critical section problem?
6. Write the structure of cooperating process that uses shared resource
7. What are monitors?
8. What is meant by starvation?
9. Define deadlock situation
10. What are essential conditions in a system for deadlock to happen?
11. List all the methods to handle deadlock situation
12. What do you mean by deadlock ignorance?
13. Define resource allocation graph
14. Is existence of cyclic in RAG confirms the occurrence of deadlock?
15. Define safe state and safe sequence
16. Define deadlock recovery
Long Answers
1. Write Peterson’s solution to critical section problem
2. Explain how semaphores can be used to solve critical section problem with producer consumer
problem
3. Explain semaphore solution to reader write problem
4. Describe monitors and its operations
5. Describe deadlock prevention mechanisms
6. Write the banker’s algorithm for deadlock avoidance
7. Consider a system that contains five processes P1, P2, P3, P4, P5 and the three resource types A, B
and C. Following are the resources types: A has 10, B has 5 and the resource type C has 7 instances.

a. Find the Need matrix


b. Is the system in safe state? If so, find the safe sequence
c. What will happen if process P1 requests one additional instance of resource type A and two
instances of resource type C? Can the request be satisfied?
Answers
1. In concurrent programming, concurrent accesses to shared resources can lead to unexpected or
erroneous behaviour, so parts of the program where the shared resource is accessed need to be
protected in ways that avoid the concurrent access. This protected section is the critical section or critical
region.

2. What is race condition?


A race condition occurs when two threads access a shared variable at the same time. The first thread
reads the variable, and the second thread reads the same value from the variable.

3. What are semaphores?


Semaphore is simply a variable that is non-negative and shared between threads. A semaphore is a
signaling mechanism, and a thread that is waiting on a semaphore can be signaled by another thread. It
uses two atomic operations, 1) Wait, and 2) Signal for the process synchronization.

4. Write about test and set instruction


The test-and-set instruction is an instruction used to write (set) 1 to a memory location and return its old
value as a single atomic (i.e., non-interruptible) operation. The caller can then "test" the result to see if
the state was changed by the call.

5. What are the requirements from any solution to critical section problem?
Mutual Exclusion, Progress, and Bounded Waiting.

6. Write the structure of cooperating process that uses shared resource

7. What are monitors?


Monitors are defined as the construct of programming language, which helps in controlling shared data
access. The Monitor is a module or package which encapsulates shared data structure, procedures,
and the synchronization between the concurrent procedure invocations.

8. What is meant by starvation?


Starvation is the problem that occurs when low priority processes get jammed for an unspecified time as
the high priority processes keep executing.

9. Define deadlock situation


In an operating system, a deadlock occurs when a process or thread enters a waiting state because a
requested system resource is held by another waiting process, which in turn is waiting for another
resource held by another waiting process.

10. What are essential conditions in a system for deadlock to happen?


The four necessary conditions for a deadlock situation are mutual exclusion, no preemption, hold and wait
and circular set.
11. List all the methods to handle deadlock situation
Prevention, avoidance, ignorance, detection and recovery

12. What do you mean by deadlock ignorance?


Deadlock Ignorance is the most widely used approach among all the mechanism. This is being used by
many operating systems mainly for end user uses. In this approach, the Operating system assumes that
deadlock never occurs. It simply ignores deadlock.

13. Define resource allocation graph


The resource allocation graph is the pictorial representation of the state of a system. As its name
suggests, the resource allocation graph is the complete information about all the processes which are
holding some resources or waiting for some resources. It also contains the information about all the
instances of all the resources whether they are available or being used by the processes.

14. Is existence of cyclic in RAG confirms the occurrence of deadlock?


No

15. Define safe state and safe sequence


A state is safe if the system can allocate resources to each process (up to its maximum) in some order
and still avoid a deadlock. More formally, a system is in a safe state only if there exists a safe sequence.

16. Define deadlock recovery


Once a deadlock is detected, you will have to break the deadlock. It can be done through different ways,
including, aborting one or more processes to break the circular wait condition causing the deadlock and
preempting resources from one or more processes which are deadlocked

Long answers
1. Write Peterson’s solution to critical section problem
Peterson’s solution provides a good algorithmic description of solving the critical-section problem and
illustrates some of the complexities involved in designing software that addresses the requirements of
mutual exclusion, progress, and bounded waiting.

do {
flag[i] = true;
turn = j;
while (flag[j] && turn == j);
/* critical section */
flag[i] = false;
/* remainder section */
}
while (true);
The structure of process Pi in Peterson’s solution. This solution is restricted to two processes that
alternate execution between their critical sections and remainder sections. The processes are numbered
P0 and P1. We use Pj for convenience to denote the other process when Pi is present; that is, j equals 1
− I, Peterson’s solution requires the two processes to share two data items –
int turn;
boolean flag[2];
The variable turn denotes whose turn it is to enter its critical section. I.e., if turn == i, then process Pi is allowed to
execute in its critical section. If a process is ready to enter its critical section, the flag array is used to indicate that.
For E.g., if flag[i] is true, this value indicates that Pi is ready to enter its critical section. With an explanation of these
data structures complete, we are now ready to describe the algorithm shown in above. To enter the critical section,
process Pi first sets flag[i] to be true and then sets turn to the value j, thereby asserting that if the other process
wishes to enter the critical section, it can do so. Turn will be set to both i and j at roughly the same time, if both
processes try to enter at the same time. Only one of these assignments will occur ultimately; the other will occur
but will be overwritten immediately. The final value of turn determines which of the two processes is allowed to
enter its critical section first. We now prove that this solution is correct. We need to show that −

• Mutual exclusion is preserved.


• The progress requirement is satisfied.
• The bounded-waiting requirement is met.
• To prove 1, we note that each Pi enters its critical section only if either flag[j] == false or turn == i. Also
note that, if both processes can be executing in their critical sections at the same time, then flag[0] ==
flag[1] == true. These two observations indicate that P0 and P1 could not have successfully executed
their while statements at about the same time, since the value of turn can be either 0 or 1 but cannot be
both. Hence, one of the processes — say, Pj — must have successfully executed the while statement,
whereas Pi had to execute at least one additional statement (“turn == j”). However, at that time, flag[j] ==
true and turn == j, and this condition will persist as long as Pj is in its critical section; as a result, mutual
exclusion is preserved.
• To prove properties 2 and 3, we note that if a process is stuck in the while loop with the condition flag[j]
== true and turn == j, process Pi can be prevented from entering the critical section only; this loop is the
only one possible. flag[j] will be == false, and Pi can enter its critical section if Pj is not ready to enter the
critical section. If Pj has set, flag[j] = true and is also executing in its while statement, then either turn ==
i or turn == j. If turn == i, Pi will enter the critical section then. Pj will enter the critical section, If turn == j.
Although once Pj exits its critical section, it will reset flag[j] to false, allowing Pi to enter its critical section.
Pj must also set turn to i, if Pj resets flag[j] to true. Hence, since Pi does not change the value of the
variable turn while executing the while statement, Pi will enter the critical section (progress) after at most
one entry by Pj (bounded waiting).

2. Explain how semaphores can be used to solve critical section problem with producer consumer problem
3. Explain semaphore solution to reader write problem
4. Describe monitors and its operations
5. Describe deadlock prevention mechanisms
6. Write the banker’s algorithm for deadlock avoidance

You might also like