Race Condition: Process Synchronization
Race Condition: Process Synchronization
Midterm
2016-17
Process Synchronization
Race condition
Race conditions usually occur if two or more processes are allowed to
modify the same shared variable at the same time.
To prevent race conditions, the operating system must perform process
synchronization to guarantee that only one process is updating a shared
variable at any one time.
Critical section
Part of the process that contains the instruction that access a shared
variable or resource.
SOFTWARE SOLUTION TO CRITICAL SECTION
Software solutions are additional codes places before or after the critical
section to make sure that race conditions will not occur and the three
requirements are met.
3 aspects:
1. Mutual exclusion guarantee that only one process may enter its
critical section at a time.
2. Progress guarantee that if a process wants to enter its critical
section and no other process is in its critical section, the process will
be able to execute in its critical section.
3. Bounded waiting the solution must guarantee that processes will
not wait for an indefinite amount of time before it can enter its
critical section.
SOLUTION 1:
SOLUTION 2:
OPERATING SYSTEM
SOLUTION TO
PROCESSES:
THE
Midterm
CRITICAL
SECTION
2016-17
PROBLEM
INVOLVING
SEVERAL
BAKERY ALGORITHM
the solution to critical section problem involving several processes
It follows the system used by bakeries in attending to their customers.
Each customer that enters the bakery gets a number. As customers enter
the bakery, the numbers increase by one. The customer that has the
lowest number will be served first.
The main problem with all the software solution to critical section problem is
busy waiting. Busy waiting is a situation where in a process keeps on checking if
a certain condition exists. Other processes that are waiting to execute their
critical section will be stuck in while loop of their programs. The CPU wastes
precious time executing the while loops.
OPERATING SYSTEM
not
Midterm
2016-17
OPERATING SYSTEM
Midterm
2016-17
Restrictions:
1. A philosopher cannot start eating unless he has both forks.
2. A philosopher cannot pick up both forks at the same time. He has to do it one at
a time.
3. He cannot get the fork that is being used by the philosopher to his right or to his
left.
OPERATING SYSTEM
Midterm
2016-17
A solution that
favors the writer
process is called
writerspreference
This solution
is often
readerssolution.
It called
still
preference
solution.
does not grant a
writer access to
the database if
there are readers
or writers already
in the database.