Beruflich Dokumente
Kultur Dokumente
Scheduling/execution
Follows an execution path through one or more programs
Has an execution state and a priority
Is the entity that is scheduled and dispatched by the OS
Multithreading
The OS supports multiple threads of execution within a single process
A process in a multithreaded environment has:
A virtual address space that holds the process image
Protected access to processors, other processes, files, and I/O resources
Within a process, there may be one or more threads and each thread has:
A thread execution state (Running, Ready, etc.)
A saved thread context when not running
An execution stack
Per-thread static storage for local variables
Access to the memory and resources of its process, shared with other threads
Examples: W2K, Solaris, Linux, Mach, OS/2
Multithreading (Cont.)
Benefits of threads:
Takes less time to create a new thread in an existing process than a new
process
Takes less time to terminate a thread than a process
Takes less time to switch between two threads within the same process
Since threads within the same process share memory and files, they can
communicate with each other without invoking the kernel
Asynchronous processing
Example: word processor that saves to disk once every minute
A second thread does periodic backups
Speed execution
Example:
One thread computes one batch of data
Other thread reads next batch from a device
Block
Thread blocks waiting on an event
Unblock
Event occurred, thread is unblocked
Finish
Thread completes, deallocate register context and stacks
10
Operation:
Application starts as a single thread running within a process managed by
kernel
Application spawns a new thread using Spawn in threads library
Threads library creates new thread and passes control to one of the threads
in Ready state using some scheduling algorithm
CS-550: Threads, SMP, and Microkernels
11
12
Disadvantages:
Transfer of control between threads within same process requires switch to
the kernel
13
Combined Approaches
Multiple ULTs from a single application are mapped
onto some (smaller or equal) number of KLTs
Thread creation done in the user space
Most of scheduling and synchronization of threads
within an application are done in the user space
Advantages:
Multiple threads within the same application can run in
parallel on multiple processors
A blocking system call does not block the entire process
Example: Solaris
CS-550: Threads, SMP, and Microkernels
14
1:1
M:1
1:M
M:M
Description
Each thread of execution is a
unique process with its own
address space and resources.
Example Systems
Traditional UNIX
implementations
Ra (Clouds), Emerald
TRIX
16
17
OS must prevent
Two processors choosing the same process
A process getting lost from the queue
19
Scheduling
With scheduling done by each processor, kernel-level multithreading must
avoid conflicts in scheduling multiple threads from the same process
simultaneously
Synchronization
Mutual exclusion and event ordering must by provided for multiple active
processes accessing shared memory and I/O
Memory Management
Paging on different processors must be coordinated when several
processors share a page or segment and decide on page replacement
21
Microkernels
Microkernel is a small operating system core containing only
essential operating systems functions
All other OS services are implemented as server processes,
execute in user mode, and communicate through messages
(device drivers, file systems, virtual memory manager,
windowing system, and security services)
The microkernel architecture replaces the traditional vertical
layered architecture and leads to a client/server architecture
within a single computer
Example:
An application opens a file by sending a message to the file system
server, creates a process or thread by sending a message to the process
server
Each of the servers can send messages to other servers (through the
kernel) and can invoke the primitive operations in the kernel
CS-550: Threads, SMP, and Microkernels
22
Extensibility
Allows the addition of new services and provision of multiple services in
the same functional area
Flexibility
New features added, existing features can be subtracted
Portability
Most of the processor-specific code is in the microkernel
Reliability
A small microkernel can be rigorously tested
23
24
26
27
Standby:
Has been selected to run on a particular processor and waits until processor
is available
Running
Has been allocated a processor and is executing
Waiting
Blocked on an event or waits for synchronization purposes
Transition
Ready to run but resources not available
Terminated
Terminated by itself, by another thread, or when the parent process
terminates
CS-550: Threads, SMP, and Microkernels
28
Benefits
No processor is idle or is executing a lower-priority thread
when a higher priority thread is ready
Multiple threads from the same process can be executing
simultaneously on multiple processors
CS-550: Threads, SMP, and Microkernels
30
Kernel threads
Fundamental entities that can be scheduled and dispatched to run on one
of the system processors
CS-550: Threads, SMP, and Microkernels
31
35