Professional Documents
Culture Documents
based on Distributed
Systems: Concepts
and Design, Edition 3,
Addison-Wesley 2001.
Learning objectives
Chapter 6:
6.1
Introduction
6.2
6.4
6.5
6.6
System layers
Figure 6.1
Applications, services
Middleware
OS: kernel,
libraries &
servers
Figure 2.1
Software and hardware service layers in distributed systems
OS2
Processes, threads,
Applications, services
communication,
...
OS1
Processes, threads,
communication, ...
Platform
Middleware
Computer &
network hardware
Computer &
network hardware
Operating system
Node 1
Node 2
Platform
Networked OS to Distributed OS
Distributed OS
Tasks:
programming interface for these resources:
abstractions such as: processes, virtual memory, files,
communication channels
Protection of the resources used by applications
Concurrent processing
Core OS functionality
Protection:
Figure 6.2
Process manager
execution mode
kernel and user
address space
Communication
manager
Memory manager
cost
Supervisor
Address space
Regions
execution environment:
Each region
an address space
synchronization and communication resources
i/o resources
Why regions:
libraries
kernel
data sharing and communication
10
Distributed OS
Auxiliary
regions
load-sharing systems
Heap
Text
0
11
Stack
process migration
12
RB copied
from RA
RA
RB
fork in unix
derived from the parent
shares the text region
a copy of the heap and stack
copy-on-write
Kernel
Shared
frame
A's page
table
B's page
table
a) Before write
13
b) After write
14
Process
Thread activations
Thread 2 makes
requests to server
Thread 1
generates
results
Requests
Activation stacks
(parameters, local variables)
N threads
Server
Client
Input-output
Receipt &
queuing
16
server
process
server
process per-connection threads
workers
I/O
remote
objects
remote
objects
a. Thread-per-request
b. Thread-per-connection
server
process
per-object threads
I/O
remote
objects
c. Thread-per-object
Issues in concurrency:
Programming support
Race condition
Deadlock
Starvation
Thread
Saved processor registers
Priority and execution state (such as
BLOCKED)
Software interrupt handling information
Execution environment identifier
20
Synchronization
create/fork
exit
join/wait
yield
Programming support
Mutual exclusion
Condition Variables
Semaphores
21
22
critical region/section
before entering critical region, try to lock
mutex_lock(l):
Consumer
mutex_lock(D)
while (no data) // count <= 0
mutex_unlock(D)
else
blocked
23
spin poll)
mutex_lock(D)
produce one item
mutex_unlock(D)
mutex_unlock(D)
24
Condition variable
cv_wait(c, m):
1.
2.
3.
4.
cv_signal(c):
wake up a thread waiting on the condition
Signaling an event
1.
2.
3.
4.
26
Producer
Consumer
mutex_lock(D)
mutex_lock(D)
counting/integer semaphores
blocked
cv_signal(yesD)
mutex_unlock(D)
else
increment s
27
28
Producer
D=1
Consumer
Count=0 // # of items
//initialization
P(D)
Consumer
P(D)
while (no data)
V(D)
P(Count)
P(D)
P(D)
V(D)
V(D)
V(Count)
sleep
P(D)
produce one item
V(D)
P(Count)
P(D)
P(D)
V(Count)
V(D)
V(D)
P(D)
P(D)
P(Count)
V(Count)
29
V(D)
V(D)
30
mutex_lock(B)
mutex_lock(A)
mutex_lock(A)
mutex_lock(B)
Exercises
do work
do work
mutex_unlock(B)
mutex_unlock(A)
mutex_unlock(A)
mutex_unlock(B)
32
Preemptive
Kernel-level
Non-preemptive
a thread can only be suspended when it de-schedules
itself (e.g. blocked by I/O, sync...) [critical region between
calls that de-schedule]
User-level
library based (pthreads, or in the language like java)
run-time system in user space manages threads
Kernel schedules processes
34
Mixed
FastThread package
Mach:
user-level code to provide scheduling hints to the kernel
Solaris:
assign each user-level thread to a kernel-level thread (multiple
user threads can be in one kernel thread)
creation/switching at the user level
scheduling at the kernel level
35
36
Process
A
P added
Process
B
SA preempted
Process
SA unblocked
SA blocked
Kernel
Virtual processors
Kernel
P idle
P needed
38