2. Processes Types
The two types of processes are
Cooperating Processes
Can affect or be affected by the execution of another
process
A process that shares data with other processes or share a
logical address space.
Independent Processes
Cannot affect or be affected by the execution of another
process
A process that does not share data.
3. The best example to see the cooperation
between two processes is Producer Consumer
problem.
It is also known as the bounded-buffer
problem.
The problem contains two processes:
the producer and the consumer.
Both processes share a common, fixed-size
buffer used as a queue.
Producer produces and consumer consumes.
4. Types
Unbounded-buffer:
◦ No practical limit on the size of the buffer
◦ Consumer may wait, producer never waits
Bounded-buffer:
◦ Assumes that there is a fixed buffer size
◦ Consumer waits for new item, producer waits if buffer
is full.
Race Conditions:
The situation where several processes access and
manipulate shared data concurrently and the out
come of execution depends on the particular order
in which the access takes place are called race
conditions
5. Critical Section (CS)
Each process has a code segment, called critical
section, in which the shared data is accessed.
When one process is executing in the critical
section, no other process is to be allowed in its
critical section. This is the problem of Critical
Section Problem.
6. Types of Section:
Each process must request permission to enter its critical
section.
1. Entry Section(ES)
Section of code implementing the request permission to
enter the critical section.
2. Exit Section (LS)
Section of code to leave the critical section which follows
Entry Section.
3. Remainder Section(RS)
Remaining code of the process after the critical section.
7. Structure of process Pi
do {
entrysection
Criticalsection
exit section
Remaindersection
} while(1);
8. 1.Mutual Exclusion
If process Pi is executing in its critical section,
then no other processes can be executing in their
critical sections
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 processes 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
9. 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.
10. Mutex is short for Mutual exclusion
Mutex lock is used to solve the critical-section
problem
Used to ensure exclusive access to data shared
between threads
Used to protect critical regions and thus prevent
race conditions
11. Illustration
A process must acquire the lock before entering a
critical section using acquire () function releases
the lock when it exits the critical section using
release() function
12. SEMOPHORES:
Semaphore is a synchronization tool
(provided by the OS) that does not require
busy waiting .
Semaphore is a variable that has an integer
value
May be initialized to a non negative number
Wait operation decrements the semaphore value
Signal operation increments semaphore value
13. A semaphore S is an integer variable that
,apart from initialization ,can only be accessed
through 2 atomic and mutually exclusive
operations:
wait(S)-Originally called P(), from Dutch proberen―to test.
signal(S) -Originally called V(), from Dutch verhogen ―to
increment.
Wait and Signal Operations
Busy-waiting implementation of these in divisible (atomic)
operations:
wait(S)
{
while(S <=0 )
;
S--;
}
15. Usage of Semaphore:
Two or more processes can cooperate by means of simple
signals such that a process can be forced to stop at a
specified place until it has received a specified signal.
Usage1:Critical Section of n Processes Problem
Shared data
Semaphore mutex;
Structure of Process Pi
do {
wait(mutex);
critical section
signal(mutex);
Remainder section
}while(1);
16. Usage2: synchronization of 2 processes
inserting the following statements inP1
s1;signal(mutex);
and the following statements in P2
wait(mutex)s2;
17. Deadlock is a situation that occurs when two
processes are waiting for the other to complete
before proceeding
Types of Deadlock
Process Deadlock
A process is deadlocked when it is waiting on an event which will
never happen
System Deadlock
A system is deadlocked when one or more processes are
deadlocked
18. System consists of resources
Resource types :
1.Reusable - Processor, memory space, I/O devices
2.Consumable – interrupts,messages
Each resource type Ri has Wi instances.
Each process utilizes a resource in sequence:
◦ request
◦ use
◦ release
19. Mutual exclusion: only one process at a time can
use a resource
Hold and wait: a process holding at least one
resource is waiting to acquire additional resources
held by other processes
No preemption: a resource can be released only
voluntarily by the process holding it, after that
process has completed its task
Deadlock can arise if four conditions hold simultaneously.
20. Circular wait: there exists a set {P0, P1,
…, Pn} of waiting processes such that P0
is waiting for a resource that is held by
P1, P1 is waiting for a resource that is
held by P2, …, Pn–1 is waiting for a
resource that is held by Pn, and Pn is
waiting for a resource that is held by P0.
21. V is partitioned into two types:
◦ P = {P1, P2, …, Pn}, the set consisting of all the
processes in the system
◦ R = {R1, R2, …, Rm}, the set consisting of all
resource types in the system
request edge – directed edge Pi Rj
assignment edge – directed edge Rj Pi
A set of vertices V and a set of edges E.
22. Process
Resource Type with 4 instances
Request edge : Pi requests instance of Rj
Claim edge : Pi is holding an instance of Rj
Pi
Pi
Rj
Rj
23.
24.
25.
26. ◦ Deadlock prevention-remove possibility of
deadlock occurring
◦ Deadlock avoidance – Identifying safe and
unsafe states
◦ Deadlock detection
◦ Deadlock recovery
27. Mutual Exclusion – not required for sharable
resources (e.g., read-only files); must hold for
non-sharable resources
Hold and Wait – must guarantee that whenever
a process requests a resource, it does not hold
any other resources
Restrain the ways request can be made
28. No Preemption –
◦ If a process that is holding some resources
requests another resource that cannot be
immediately allocated to it, then all resources
currently being held are released
Circular Wait – impose a total ordering of all
resource types, and require that each process
requests resources in an increasing order of
enumeration
29. Resource-allocation state is defined by
the number of available and allocated
resources, and the maximum demands
of the processes
30. When a process requests an available resource, system
must decide if immediate allocation leaves the system
in a safe state
System is in safe state if there exists a sequence <P1,
P2, …, Pn> of ALL the processes in the systems such
that for each Pi, the resources that Pi can still request
can be satisfied by currently available resources +
resources held by all the Pj, with j < I
31. If a system is in safe state no
deadlocks
If a system is in unsafe state
possibility of deadlock
Avoidance ensure that a system
will never enter an unsafe state.