Академический Документы
Профессиональный Документы
Культура Документы
Concurrency:
Deadlock and
Starvation
Ninth Edition, Global Edition
By William Stallings
c b 2 3 2
4 d a 4 1
Get A
3 deadlock P and Q
B
inevitable want B
Required
5
Get B
4
6
Progress
Get A Get B Release A Release B of P
= both P and Q want resource A
A
= both P and Q want resource B
Required
1 2 3
Release
A
4
A Release P and Q
Required B want A
P and Q
Get A
want B
B
Required
5
Get B
Progress
Get A Release A Get B Release B of P
Consumable
• One that can be created (produced) and
destroyed (consumed)
• Interrupts, signals, messages, and
information
• In I/O buffers
Ra Ra
He He
ld ld
s ts by s ts by
q ue q ue
Re Re
P1 P2 P1 P2
ts ts
He es He ue
s
ld e qu ld eq
by R by R
Rb Rb
Ra Rb Rc Rd
Circular Wait
The circular wait condition can be prevented by defining a linear
ordering of resource types
R1 R2 R3 R1 R2 R3
9 3 6 0 1 1
Resource vector R Available vector V
R1 R2 R3 R1 R2 R3
9 3 6 6 2 3
Resource vector R Available vector V
R1 R2 R3 R1 R2 R3
9 3 6 7 2 3
Resource vector R Available vector V
R1 R2 R3 R1 R2 R3
9 3 6 9 3 4
Resource vector R Available vector V
R1 R2 R3 R1 R2 R3
9 3 6 1 1 2
Resource vector R Available vector V
R1 R2 R3 R1 R2 R3 R1 R2 R3
P1 3 2 2 P1 2 0 1 P1 1 2 1
P2 6 1 3 P2 5 1 1 P2 1 0 2
P3 3 1 4 P3 2 1 1 P3 1 0 3
P4 4 2 2 P4 0 0 2 P4 4 2 0
Claim matrix C Allocation matrix A C–A
R1 R2 R3 R1 R2 R3
9 3 6 0 1 1
Resource vector R Available vector V
Classes of resources
Swappable space
Blocks of memory on secondary storage for use in swapping processes
Process resources
Assignable devices, such as tape drives, and files
Main memory
Assignable to processes in pages or segments
Internal resources
Such as I/O channels
No philosopher P0
P4
must starve to
death (avoid
deadlock and
starvation)
Figure 6.11 Dining Arrangement for Philosophers
}
void main()
{
parbegin (philosopher (0), philosopher (1), philosopher (2),
philosopher (3), philosopher (4));
}
Shared
Pipes Messages
memory
Semaphores Signals
Two types:
• Named
• Unnamed
Consists of:
Internally:
Implemented as functions within the kernel and are more efficient
than user-visable semaphores
Reader-writer semaphores
The shared resources that the RCU mechanism protects must be accessed via
a pointer
The RCU mechanism provides access for multiple readers and writers to a
shared resource
Mutual
exclusion
(mutex) Semaphores
locks
In addition to the
concurrency
mechanisms of
UNIX SVR4,
Solaris supports
four thread
synchronization
Condition primitives:
variables Readers/writer
locks
(b) Semaphore
The thread that locks the mutex must be the one that unlocks it
“Lock-free”
1
2
3
4
5
6
7
8