Lecture 3 - Chap - 4
Lecture 3 - Chap - 4
Lecture 3 - Chap - 4
Microkernels
Chapter 4
Multithreading
Operating system supports multiple threads of execution within a single
process
MS-DOS
Java
run-time
environment
Single-threaded Multithreaded
Multithreading
Each thread in a process has
– an execution state (running, ready, etc.)
– saved thread context when not running
– an execution stack
– some per-thread static storage for local variables
– access to the memory and resources of its process
• all threads of a process share this
Multithreading
► Thread control block containing register values, priority and other
state information.
Benefits of Threads
Takes less time to create a new thread than a new
process
Take less time to terminate a thread
Take 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
Drawbacks of Threads
Requires careful design (shared variables)
Hard to debug because the interaction between
threads very hard to control.
Multithreading
Uses of threads in a single-user multiprocessing
system
Foreground and background work, example: one thread
could display menus and read user input, another thread
executes user commands
Asynchronous processing: a thread to backup data
periodically
Speed of execution: on a multiprocessor system, multiple
threads can execute simultaneously
Modular program structure: programs with many activities
or input and output can implement using threads
Multithreading
formatting
Spell &
ABC
grammar
checking
Auto saving
editing
Word processor
AST
Multithreading
AST
Multithreading
Suspending a process involves suspending all
threads of the process since all threads share the
same address space
Termination of a process, terminates all threads
within the process
Thread States
States associated with a change in thread state
– Spawn
• A thread within a process may spawn another thread
– Block
– Unblock
– Finish
• De-allocate register context and stacks
In a single-threaded program, the results in the above RPCs are obtained
in sequence, so that the program has to wait for a response from each
server in turn.
Remote Procedure Call Using Threads
Unblocked
Multiprogramming on Uniprocessor
► 3 possible cases/occurrence:
ULT States vs. Process States
► Possible occurrence 1:
Application in thread 2 makes a I/O call that blocks
process B, the kernel switches to another process.
Although thread 2 is perceived in Running state by the
thread library, it is not actually executed on a processor.
ULT States vs. Process States
► Possible occurrence 2:
Process B exhausted its time slice and is placed in Ready
state, but the data structure managed by thread library
shows that thread 2 is still in running state. Again, Thread
2 is not actually executed on a processor.
ULT States vs. Process States
► Possible occurrence 3:
Thread 2 needs some actions performed by thread 1.
Thread 2 is blocked and thread 1 is executing. Process B
still remains in Running state.
Advantages of ULTs
shared
Parallel Applications
Sequential Applications Parallel Programming Environments
Cluster Middleware
PC/Workstation PC/ Workstation PC/ Workstation PC/ Workstation PC/ Workstation
Comm.
Local SW
memory Comm.
Local SW
memory Comm.
Local SW
memory Comm.
Local SW
memory Comm.
Local SW
memory
• Each processor has its local memory with the address space
available only for this processor.
• Processors can exchange data through the interconnection network
by means of communication through the message passing.
Examples of Cluster
https://computing.llnl.gov/tutorials/linux_clusters/
Examples of Cluster
http://raspberrywebserver.com/raspberrypicluster/raspberry-pi-cluster.html
Multiprocessor OS Design Considerations
Implemen
ted as
server
processes
or monolithic
Benefits of Microkernel Organization
* Linux does not really differentiate process and thread from kernel point of
view. The kernel just views thread as another process with shared
resources.
Linux Process/Thread Model