Lecture Slide 5 OS Spring 25
Lecture Slide 5 OS Spring 25
1. Overview
2. Multicore Programming *
3. Multithreading Models *
4. Thread Libraries
5. Implicit Threading
6. Threading Issues *
7. Operating System Examples
Single and Multithreaded Processes
Multithreaded Server Architecture
Benefits MT (Multi Thread)
Responsiveness – may allow continued execution if part of
process is blocked, especially important for user interfaces
Resource Sharing – threads share resources of process, easier
than shared memory or message passing
Economy – cheaper than process creation, thread switching
lower overhead than context switching
Scalability – process can take advantage of multicore
architectures (utilization of Multiple Processor)
Multicore Programming
Multicore or multiprocessor systems putting pressure on programmers,
challenges include:
Dividing activities
Balance
Data splitting
Data dependency
Testing and debugging
Parallelism implies a system can perform more than one task simultaneously
Task parallelism – Task parallelism involves distributing not data but tasks
(threads) across multiple computing cores.
That is, if application is 75% parallel / 25% serial, moving from 1 to 2 cores results in speedup
of 1.6 times
As N approaches infinity, speedup approaches 1 / S
Serial portion of an application has disproportionate effect on performance gained by
adding additional cores
But does the law take into account contemporary multicore systems?
Amdahl’s Law
User Threads and Kernel Threads
Many-to-One
One-to-One
Many-to-Many
Many-to-One
Many user-level threads mapped to
single kernel thread
One thread blocking causes all to
block
Multiple threads may not run in
parallel on multicore system because
only one may be in kernel at a time
Few systems currently use this model
Examples:
Solaris Green Threads
GNU Portable Threads
One-to-One
Each user-level thread maps to kernel thread
Signal handling
Synchronous and asynchronous
Thread-local storage
Scheduler Activations
Semantics of fork() and exec()
Does fork()duplicate only the calling thread or all threads?
Some UNIXes have two versions of fork
Why and when to use
Exec() immediately after Fork(), then duplication of all process is not
needed
No Exec() after Fork(), then duplication of all process is needed
Every signal has default handler that kernel runs when handling signal
User-defined signal handler can override default
For single-threaded, signal delivered to process
Signal Handling (cont’d)
Linux Threads
Windows Threads
Windows API – primary API for Windows applications