Professional Documents
Culture Documents
Chapter 4: Threads & Concurrency: Silberschatz, Galvin and Gagne ©2018 Operating System Concepts
Chapter 4: Threads & Concurrency: Silberschatz, Galvin and Gagne ©2018 Operating System Concepts
Concurrency
q Overview
q Multicore Programming
q Multithreading Models
q Thread Libraries
q Implicit Threading
q Threading Issues
q Types of parallelism
o N processing cores
q But does the law take into account contemporary multicore systems?
o POSIX Pthreads
o Windows threads
o Java threads
q Many-to-One
q One-to-One
q Many-to-Many
q Examples:
q Examples
o Windows
o Linux
Operating System Concepts ñ 9th Edition 4.21 Silberschatz, Galvin and Gagne ©2013
Operating System Concepts 25 Silberschatz, Galvin and Gagne ©2018
Windows Multithreaded C Program
q Creating a thread:
q Waiting on a thread:
o Thread Pools
o Fork-Join
o OpenMP
q Advantages:
o Usually slightly faster to service a request with an existing thread than
create a new thread
o Allows the number of threads in the application(s) to be bound to the size
of the pool
o Separating task to be performed from mechanics of creating task allows
different strategies for running task
4 i.e., Tasks could be scheduled to run periodically
q Block is in “^{ }” :
ˆ{ printf("I am a block"); }
o serial – blocks removed in FIFO order, queue is per process, called main
queue
– QOS_CLASS_USER_INTERACTIVE
– QOS_CLASS_USER_INITIATED
– QOS_CLASS_USER_UTILITY
– QOS_CLASS_USER_BACKGROUND
q Signal handling
o Asynchronous or deferred
q Thread-local storage
q Scheduler Activations
q Every signal has a default handler that kernel runs when handling
signal
o User-defined signal handler can override default
o Asynchronous cancellation
terminates the target thread
immediately
q Thread-local storage (TLS) allows each thread to have its own copy
of data
q Useful when you do not have control over the thread creation process
(i.e., when using a thread pool)
q Windows Threads
q Linux Threads
o A thread id
o Separate user and kernel stacks for when thread runs in user mode or
kernel mode
o Private data storage area used by run-time libraries and dynamic link
libraries (DLLs)
q The register set, stacks, and private storage area are known as the
context of the thread