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

Race Condition: Process Synchronization

The document discusses process synchronization and solutions to the critical section problem. It describes race conditions that can occur when multiple processes access shared variables simultaneously. To prevent race conditions, process synchronization is needed to ensure only one process is in its critical section at a time. Several software solutions and hardware solutions are presented to solve the critical section problem, including Peterson's algorithm and the bakery algorithm. Finally, classic synchronization problems like the dining philosophers problem and readers-writers problem are discussed.

Uploaded by

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

Race Condition: Process Synchronization

The document discusses process synchronization and solutions to the critical section problem. It describes race conditions that can occur when multiple processes access shared variables simultaneously. To prevent race conditions, process synchronization is needed to ensure only one process is in its critical section at a time. Several software solutions and hardware solutions are presented to solve the critical section problem, including Peterson's algorithm and the bakery algorithm. Finally, classic synchronization problems like the dining philosophers problem and readers-writers problem are discussed.

Uploaded by

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

OPERATING SYSTEM

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:

SOLUTION 3 (PETERSONs ALGORITHM) :

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.

Hardware solutions to the critical section problem:


Disabling interrupts
Special Hardware Instructions
o Test_and_set instruction is an atomic instruction, only one process
can enter its critical section at any one time

OPERATING SYSTEM

not

Midterm

2016-17

Semaphore a tool used to


solve more complex
synchronization
problems and does
use busy waiting.
Only the following operations
can access it once initialized

OPERATING SYSTEM

Midterm

2016-17

Classic synchronization problems


The dining philosophers problem
Represents how several processes contend for the limited resources of the
computer system.

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.

The readers and writers problem


represents access to a database
Readers are processes that only examine or read data stored in a database
Writers are processes that modify or update the data.
Several readers are allowed simultaneous access to the same database
file since they do not change any data.
Writer must have exclusive access to the database.
If a reader is currently reading data from the database, a writer cannot
enter.
If a writer is currently accessing the database, other writers (and also
readers) are not allowed to access the database.

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.

You might also like