0% found this document useful (0 votes)
7 views14 pages

Understanding Race Conditions and CS Solutions

The document discusses race conditions and the critical-section problem, where multiple processes access shared data, potentially leading to inconsistent results. It outlines the requirements for a correct solution: mutual exclusion, progress, and bounded waiting, and describes the structure of processes and their critical sections. Various types of solutions to the critical-section problem are also mentioned, including software, hardware, operating system, and programming language solutions.

Uploaded by

ABHIJEET KUMAR
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)
7 views14 pages

Understanding Race Conditions and CS Solutions

The document discusses race conditions and the critical-section problem, where multiple processes access shared data, potentially leading to inconsistent results. It outlines the requirements for a correct solution: mutual exclusion, progress, and bounded waiting, and describes the structure of processes and their critical sections. Various types of solutions to the critical-section problem are also mentioned, including software, hardware, operating system, and programming language solutions.

Uploaded by

ABHIJEET KUMAR
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

Race Condition

 It is a situation in which

 multiple threads or processes read and write a


shared data item and,

 the final result depends on the relative timing of


their execution.
The Critical-Section Problem
The Critical-Section Problem
• n processes competing to use some shared data.
• No assumptions may be made about speeds or
the number of CPUs.
• Each process has a code segment, called
Critical Section (CS), in which the shared data
is accessed.
• Problem – ensure that when one process is
executing in its CS, no other process
is allowed to execute in its CS.
6 A. Frank - P. Weisberg
CS Problem Dynamics (1)
• When a process executes code that manipulates
shared data (or resource), we say that the
process is in it’s Critical Section (for that
shared data).
• The execution of critical sections must be
mutually exclusive: at any time, only one
process is allowed to execute in its critical
section (even with multiple processors).
• So each process must first request permission
to enter its critical section.
7 A. Frank - P. Weisberg
CS Problem Dynamics (2)
• The section of code implementing this request is
called the Entry Section (ES).
• The critical section (CS) might be followed by a
Leave/Exit Section (LS).
• The remaining code is the Remainder Section (RS).
• The critical section problem is to design a protocol
that the processes can use so that their action will not
depend on the order in which their execution is
interleaved (possibly on many processors).

8 A. Frank - P. Weisberg
General structure of process Pi (other is Pj)

do {
entry section
critical section
leave section
remainder section
} while (TRUE);
• Processes may share some common variables
to synchronize their actions.
9 A. Frank - P. Weisberg
Solution to Critical-Section Problem
• There are 3 requirements that must stand for a
correct solution:
1. Mutual Exclusion
2. Progress
3. Bounded Waiting
• We can check on all three requirements in
each proposed solution, even though the
non-existence of each one of them is enough
for an incorrect solution.
10 A. Frank - P. Weisberg
Solution to CS Problem – Mutual Exclusion
1. Mutual Exclusion – If process Pi is executing
in its critical section, then no other processes
can be executing in their critical sections.
• Implications:
 Critical sections better be focused and short.
 Better not get into an infinite loop in there.
 If a process somehow halts/waits in its critical
section, it must not interfere with other processes.

11 A. Frank - P. Weisberg
Solution to CS Problem – Progress
2. Progress – If no process is executing in its
critical section and there exist some processes
that wish to enter their critical section, then
the selection of the process that will enter the
critical section next cannot be postponed
indefinitely:
• If only one process wants to enter, it should be
able to.
• If two or more want to enter, one of them should
succeed.
12 A. Frank - P. Weisberg
Solution to CS Problem – Bounded Waiting
3. Bounded Waiting – A bound must exist on
the number of times that other processes are
allowed to enter their critical sections after a
process has made a request to enter its critical
section and before that request is granted.
• Assume that each process executes at a nonzero
speed.
• No assumption concerning relative speed of the n
processes.

13 A. Frank - P. Weisberg
Types of solutions to CS problem
• Software solutions –
– algorithms who’s correctness does not rely on any
other assumptions.
• Hardware solutions –
– rely on some special machine instructions.
• Operating System solutions –
– provide some functions and data structures to the
programmer through system/library calls.
• Programming Language solutions –
– Linguistic constructs provided as part of a language.
14 A. Frank - P. Weisberg

You might also like