Beruflich Dokumente
Kultur Dokumente
Week 3
1/26
Agenda
What is a thread?
Multithreading?
Benefits of Threads
Threading Mechanisms
Threading Issues
Operating System Examples
Preserving Confidentiality in Virtual Machine Checkpointing and Role Based Access Control
2/26
What is a Thread?
Thread: basic unit of CPU utilization.
3/26
Multithreading
code
registers
data
files
code
data
files
stack
registers
registers
registers
stack
stack
stack
thread
thread
Single-threaded process
multithreaded process
Why Multithread?
Key idea: if process has multiple threads, it can perform
multiple tasks at a time.
Example: a Web server is accessed by thousands of
clients simultaneously. How can we service the clients?
Single process: services clients one at a time slow!
Multiple processes: for each client, fork a copy of the
server.
Faster than a single process: multiple processes can service
clients in parallel.
Wasteful: if each process will perform identical tasks, then
why duplicate ALL process resources? (e.g. memory, as fork()
does).
5/26
Benefits of Multithreading
Multicore Programming
Multicore systems are pervasive:
OSs should support concurrent execution on multiple cores.
Application developers: should design multithreaded
programs a challenging task!
Dividing activities: how can we split our program into a set of
concurrent tasks?
Balance: how can we fairly divide the workload among multiple
tasks?
Data splitting: how can the data be split among multiple tasks?
Data dependency: if task T2 depends on the data from task T1,
then T1 and T2 must be properly synchronized.
Testing and debugging: much harder than with a single thread!
7/26
Multithreading Models
Win32 Threads
Java Threads
Kernel thread
9/26
Kernel thread
Kernel thread
One-to-one:
Results in true concurrency.
The overhead of creating a thread is high.
Most implementations limit the number of threads.
Many-to-many:
Aims to get the best of both worlds.
12/26
Thread Libraries
Thread library: provides an API for creating and managing
threads.
Implementing a thread library:
In user space: invoking an API function does not result in a
system call (because no OS intervention needed) fast!
In kernel space: invoking an API function call results in a
system call.
13/26
15/26
));
if (atoi(argv[1] ) < 0)
{ fprintf(stderr, "%d must be >= 0\n", atoi(argv[1]
}
return -1;
}
16/26
Preserving Confidentiality in Virtual Machine Checkpointing and Role Based Access Control
17/26
18/26
19/26
20/26
Preserving Confidentiality in Virtual Machine Checkpointing and Role Based Access Control
21/26
22/26
23/26
Preserving Confidentiality in Virtual Machine Checkpointing and Role Based Access Control
24/26
25/26