Académique Documents
Professionnel Documents
Culture Documents
• Introduction
• Threads Usage
• Design Issues for Thread Packages
• Implementing a Thread Package
1
Process vs. Thread (1)
2
Process vs. Thread (2)
• Processes
– Inter-process communication is expensive:
need to context switch
– Secure: one process cannot corrupt another
process
3
Process vs. Thread (3)
• Threads
– Inter-thread communication cheap: can use
process memory and may not need to
context switch
– Not secure: a thread can write the memory
used by another thread
4
1.Intoduction
• Threads are mini processes or
light weight processes.
5
Thread Characteristics
• All the threads have same address
space, which means that they also
share the same global variables.
Per Thread
Items
Program counter
Stack
Register
Child threads
6
State
2.Thread Usage
Dispatcher
File Thread
Server Worker
Process thread
Shared
block
cache
Request for
Kernel
Work arrives 8
Design Issues for thread
Packages
• Thread management
• Thread creation and destruction
• Accessing Data
• Handling Deadlock
9
Accessing Data
• Access to shared data is done using
critical regions.
• Critical regions are implemented in
threads package using mutex and a
synchronization feature called
condition variable.
• Mutex is a binary semaphore.
• condition variable is similar
condition variable used for
synchronization in monitors 10
Handling Deadlock
Critical region
Thread_1 locks
mutex m1 Thread_2 R2
m2
R1
R3
R4
Thread_1 m1
11
Handling Deadlocks
Lock mutex; lock mutex;
check data structures; mark resource
as busy;
while(resource busy) unlock mutex;
wait(condition variable)
wakeup(condition variable);
mark resource as busy;
Unlock mutex;
12
Threads implimentation:
• Threads are generally provided in the
form of thread package.
Kernel
space
Kernel
16
Scheduler Activations
• Scheduler Activations is an approach
to combine user-space and kernel
threads.