operating systems - university of limerick
TRANSCRIPT
AnnouncementsThreads – §4, SGG
Operating Systems
P. Healy
CS1-08Computer Science Bldg.
tel: [email protected]
Autumn 2019–2020
P. Healy (University of Limerick) CS4023 Autumn 2019–2020 1 / 24
AnnouncementsThreads – §4, SGG
Outline
1 Announcements
2 Threads – §4, SGGMultithreading ModelsThreading IssuesThread Libraries
P. Healy (University of Limerick) CS4023 Autumn 2019–2020 2 / 24
AnnouncementsThreads – §4, SGG
Announcements
Tute / problem solving session now moved to Monday,13.00, KBG12 today onwards!SETMid-term: bubbling up to the surface of my head
P. Healy (University of Limerick) CS4023 Autumn 2019–2020 3 / 24
AnnouncementsThreads – §4, SGG
Password Problems
If you’ve forgotten your password ...... but then, one thing leads to another
P. Healy (University of Limerick) CS4023 Autumn 2019–2020 4 / 24
AnnouncementsThreads – §4, SGG
Multithreading ModelsThreading IssuesThread Libraries
Outline
1 Announcements
2 Threads – §4, SGGMultithreading ModelsThreading IssuesThread Libraries
P. Healy (University of Limerick) CS4023 Autumn 2019–2020 5 / 24
AnnouncementsThreads – §4, SGG
Multithreading ModelsThreading IssuesThread Libraries
Single and Multithreaded Processes
Process: unit of resourcesThread: unit of scheduling and execution
P. Healy (University of Limerick) CS4023 Autumn 2019–2020 6 / 24
AnnouncementsThreads – §4, SGG
Multithreading ModelsThreading IssuesThread Libraries
Benefits of Threads
ResponsivenessResource SharingEconomy
in Solaris, creating a process is aboutthan is creating a thread, and context switching is about
Utilization of multiprocessor architectures
P. Healy (University of Limerick) CS4023 Autumn 2019–2020 7 / 24
AnnouncementsThreads – §4, SGG
Multithreading ModelsThreading IssuesThread Libraries
Kernel vs. User Threads
Kernel threads are supported by almost every operatingsystem currently; relatively expensive to createUser threads Thread management done by user-levelthreads library
Three primary thread libraries:POSIX PthreadsWin32 threadsJava threads
Ultimately, some relationship that maps from user- tokernel-thread must exist between the two: “shadowing”
StackOverflow Explanation
P. Healy (University of Limerick) CS4023 Autumn 2019–2020 8 / 24
AnnouncementsThreads – §4, SGG
Multithreading ModelsThreading IssuesThread Libraries
Three Thread Models
Many-to-OneOne-to-OneMany-to-Many
Wikipedia’s Processes, kernel threads and Kernel models
P. Healy (University of Limerick) CS4023 Autumn 2019–2020 9 / 24
AnnouncementsThreads – §4, SGG
Multithreading ModelsThreading IssuesThread Libraries
Many-to-One Thread Model
Many user-level threadsmapped to single
All threads blocked ifkernel thread is blockedExamples:
Solaris Green ThreadsGNU Portable Threads
One kernel thread ⇒ noparallelism (multi-coresuseless)
P. Healy (University of Limerick) CS4023 Autumn 2019–2020 10 / 24
AnnouncementsThreads – §4, SGG
Multithreading ModelsThreading IssuesThread Libraries
One-to-One Thread Model
Each user-level thread maps to kernel threadBlocking on a single kernel thread now not an issue butrelatively high cost of kernel thread setup works againstthis approachExamples
Windows NT/XP/2000LinuxSolaris 9 and later
P. Healy (University of Limerick) CS4023 Autumn 2019–2020 11 / 24
AnnouncementsThreads – §4, SGG
Multithreading ModelsThreading IssuesThread Libraries
Many-to-Many Thread Model
Allows many user levelthreads to be mappedto many kernel threadsAllows the operatingsystem to create asufficient number ofkernel threads
Solaris prior to v. 9Windows NT/2000with the ThreadFiberpackage
P. Healy (University of Limerick) CS4023 Autumn 2019–2020 12 / 24
AnnouncementsThreads – §4, SGG
Multithreading ModelsThreading IssuesThread Libraries
Two-level Model
Similar toprevious M:M,except that itallows a userthread to bebound to a kernelthreadExamples
IRIXHP-UXTru64 UNIXSolaris 8 andearlier
P. Healy (University of Limerick) CS4023 Autumn 2019–2020 13 / 24
AnnouncementsThreads – §4, SGG
Multithreading ModelsThreading IssuesThread Libraries
Outline
1 Announcements
2 Threads – §4, SGGMultithreading ModelsThreading IssuesThread Libraries
P. Healy (University of Limerick) CS4023 Autumn 2019–2020 14 / 24
AnnouncementsThreads – §4, SGG
Multithreading ModelsThreading IssuesThread Libraries
Some concerns
Semantics of fork() and exec() system callsDoes fork() duplicate only the calling thread or allthreads?
Thread cancellationTerminating a thread before it has finishedTwo general approaches:
Asynchronous cancellation terminates the target threadimmediatelyDeferred cancellation allows the target thread toperiodically check if it should be cancelled
P. Healy (University of Limerick) CS4023 Autumn 2019–2020 15 / 24
AnnouncementsThreads – §4, SGG
Multithreading ModelsThreading IssuesThread Libraries
Some concerns (contd.)
Signal handlingSignals are used in UNIX systems to notify a process that aparticular event has occurredA signal handler is used to process signals:
Signal is generated by particular eventSignal is delivered to a processSignal is handled
Possibilities:Deliver the signal to the thread to which the signal appliesDeliver the signal to every thread in the processDeliver the signal to certain threads in the processAssign a specific thread to receive all signals for the process
P. Healy (University of Limerick) CS4023 Autumn 2019–2020 16 / 24
AnnouncementsThreads – §4, SGG
Multithreading ModelsThreading IssuesThread Libraries
Some concerns (contd.)
Thread poolsCreate a number of threads in a pool where they await workAdvantages
Usually slightly faster to service a request with an existingthread than create a new threadAllows the number of threads in the application(s) to bebound to the size of the pool
Thread-specific dataAllows each thread to have its own copy of dataUseful when you do not have control over the threadcreation process (i.e., when using a thread pool)
P. Healy (University of Limerick) CS4023 Autumn 2019–2020 17 / 24
AnnouncementsThreads – §4, SGG
Multithreading ModelsThreading IssuesThread Libraries
Scheduler activations
Both M:M and Two-level models require communication tomaintain the appropriate number of kernel threadsallocated to the applicationScheduler activations provide upcalls - a communicationmechanism from the kernel to the thread libraryThis communication allows an application to maintain thecorrect number of kernel threads
P. Healy (University of Limerick) CS4023 Autumn 2019–2020 18 / 24
AnnouncementsThreads – §4, SGG
Multithreading ModelsThreading IssuesThread Libraries
Outline
1 Announcements
2 Threads – §4, SGGMultithreading ModelsThreading IssuesThread Libraries
P. Healy (University of Limerick) CS4023 Autumn 2019–2020 19 / 24
AnnouncementsThreads – §4, SGG
Multithreading ModelsThreading IssuesThread Libraries
Pthreads
A POSIX standard (IEEE 1003.1c) API for thread creationand synchronizationAPI specifies behavior of the thread library, implementationis up to development of the libraryCommon in UNIX operating systems (Solaris, Linux, MacOS X)
P. Healy (University of Limerick) CS4023 Autumn 2019–2020 20 / 24
AnnouncementsThreads – §4, SGG
Multithreading ModelsThreading IssuesThread Libraries
Java Threads
Java threads are managed by the JVM which runs onsome OSJava threads may be created by:
Extending Thread classImplementing the Runnable interface
Java thread states:
P. Healy (University of Limerick) CS4023 Autumn 2019–2020 21 / 24
AnnouncementsThreads – §4, SGG
Multithreading ModelsThreading IssuesThread Libraries
Linux Threads
Linux refers to them as tasks rather than threadsThread creation is done through clone() system callclone() allows a child task to share the address space ofthe parent task (process)amount of “data sharing” with parent controlled by followingflags
P. Healy (University of Limerick) CS4023 Autumn 2019–2020 22 / 24
AnnouncementsThreads – §4, SGG
Multithreading ModelsThreading IssuesThread Libraries
Windows XP Threads
Implements the one-to-one mappingEach thread contains
A thread idRegister setSeparate user and kernel stacksPrivate data storage area
The register set, stacks, and private storage area areknown as the context of the threadsThe primary data structures of a thread include:
ETHREAD (executive thread block)KTHREAD (kernel thread block)TEB (thread environment block)
P. Healy (University of Limerick) CS4023 Autumn 2019–2020 23 / 24
AnnouncementsThreads – §4, SGG
Multithreading ModelsThreading IssuesThread Libraries
Windows Vista Enhancements
Thread pool significantly enhanced to improve reliability,performance, and API simplicitySome specific examples of Windows Vista thread poolenhancements include:
Cleanup groups - introduce the ability to clean up pendingthread pool requests on process shutdownMultiple pools per process, each of which is scheduledindependently. This significantly improves responsivenessas well as code isolationPerformance. The thread pool is optimized to provide thebest possible processor usage and to reduce pressure onsystem memory. Thread recycling, maintaining a number ofrunning threads that is proportional to the number ofprocessors, smart load balancing, and work assignment areused to gain maximum performance from the thread pool.
P. Healy (University of Limerick) CS4023 Autumn 2019–2020 24 / 24