Processes and Threads - The College of New Jersey

Download Report

Transcript Processes and Threads - The College of New Jersey

What is a Thread?
A thread is similar to a process, but it typically
consists of just the flow of control. Multiple
threads use the address space of a single
process.
The complete name is: Thread of Execution
1
The Thread Model
(a) Three processes each with one thread
(b) One process with three threads
2
The Thread Model
• Items shared by all threads in a process
• Items private to each thread
3
The Thread Model
Each thread has its own stack
4
Why Do We Use Threads?
•To simplify programs in which multiple activities go on at once.
•Easier to create and destroy because they have no resources
attached to them - they share common memory.
•Performance gain, when there is substantial amounts of both
computing and I/O.
A word processor with three threads
5
A multithreaded Web server
6
Rough outline of code for web server
(a) Dispatcher thread
(b) Worker thread
7
Three ways to construct a server
8
Implementing Threads in User Space
A user-level threads package
9
Implementing Threads in the Kernel
A threads package managed by the kernel
10
Hybrid Implementations
Multiplexing user-level threads onto kernellevel threads
11