






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An overview of threads in operating systems, covering topics such as multicore programming, multithreading models, thread libraries, implicit threading, and threading issues. It discusses the benefits of using threads, including responsiveness, resource sharing, economy, and scalability. The document also explores different types of parallelism, including data parallelism and task parallelism, and examines amdahls law in relation to multicore programming. Additionally, it covers user threads, kernel threads, multithreading models, and specific threading issues like semantics of fork() and exec(), signal handling, thread cancellation, and thread-local storage. The document also provides examples of windows and linux threads.
Typology: Lecture notes
1 / 10
This page cannot be seen from the preview
Don't miss anything!







Operating System Concepts – 9th^ Edition Silberschatz, Galvin and Gagne ©
Operating System Concepts – 9th^ Edition 4.2 Silberschatz, Galvin and Gagne ©
(^) Overview (^) Multicore Programming (^) Multithreading Models (^) Thread Libraries (^) Implicit Threading (^) Threading Issues (^) Operating System Examples Operating System Concepts – 9th^ Edition 4.3 Silberschatz, Galvin and Gagne ©
(^) To introduce the notion of a thread—a fundamental unit of CPU utilization that forms the basis of multithreaded computer systems (^) To discuss the APIs for the Pthreads, Windows, and Java thread libraries (^) To explore several strategies that provide implicit threading (^) To examine issues related to multithreaded programming (^) To cover operating system support for threads in Windows and Linux Operating System Concepts – 9th^ Edition 4.4 Silberschatz, Galvin and Gagne ©
(^) Most modern applications are multithreaded (^) Threads run within application (^) Multiple tasks with the application can be implemented by separate threads (^) Update display (^) Fetch data (^) Spell checking (^) Answer a network request (^) Process creation is heavy-weight while thread creation is light- weight (^) Can simplify code, increase efficiency (^) Kernels are generally multithreaded
Operating System Concepts – 9th^ Edition 4.6 Silberschatz, Galvin and Gagne ©
(^) 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 multiprocessor architectures Operating System Concepts – 9th^ Edition 4.7 Silberschatz, Galvin and Gagne ©
(^) 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 (^) Concurrency supports more than one task making progress (^) Single processor / core, scheduler providing concurrency Operating System Concepts – 9th^ Edition 4.8 Silberschatz, Galvin and Gagne ©
(^) Types of parallelism (^) Data parallelism – distributes subsets of the same data across multiple cores, same operation on each (^) Task parallelism – distributing threads across cores, each thread performing unique operation (^) As # of threads grows, so does architectural support for threading
Operating System Concepts – 9th^ Edition 4.13 Silberschatz, Galvin and Gagne ©
(^) Many-to-One (^) One-to-One (^) Many-to-Many
Operating System Concepts – 9th^ Edition 4.19 Silberschatz, Galvin and Gagne ©
(^) Thread library provides programmer with API for creating and managing threads (^) Two primary ways of implementing (^) Library entirely in user space (^) Kernel-level library supported by the OS
Operating System Concepts – 9th^ Edition 4.25 Silberschatz, Galvin and Gagne ©
(^) A concurrency framework developed by Apple (macOS/iOS) that uses dispatch queues for managing multiple tasks efficiently. (^) Tasks are automatically scheduled on available CPU cores. (^) No need to create/join threads (^) Automatically balances workload (^) Example
(^) When working with multithreading, several issues arise due to the complexity of managing multiple threads in a process. Below are some of the key challenges:
(^) The behavior of fork() and exec() changes when multiple threads are present. The key question is: (^) If one thread calls fork(), should the new process copy all threads or just the calling thread? (^) UNIX Solutions: (^) UNIX systems provide two versions of fork(): (^) Fork Type Behavior (^) Full Process Fork Duplicates all threads of the parent process (^) Threaded Fork Only the calling thread is duplicated in the child process (^) Best Practice: In a multithreaded program, after fork(), call exec() to start a new process, avoiding inconsistencies caused by duplicated threads. Operating System Concepts – 9th^ Edition 4.28 Silberschatz, Galvin and Gagne ©
(^) Signal is an asynchronous notification sent to a process (or thread) by the operating system or another process to inform it that a specific event has occurred. (^) In a single-threaded program, signals are delivered directly to the process, but in multithreading, handling becomes more complex. (^) Types of Signal Handlings (^) Synchronous Signals: Occur as a direct result of thread execution (e.g., division by zero, invalid memory access). These are delivered to the thread that caused them. (^) Asynchronous Signals: Sent externally (e.g., SIGTERM, SIGINT from the keyboard). These signals must be handled properly in multithreaded environments. (^) Handling Signals in Threads: Three common strategies for signal delivery:
Operating System Concepts – 9th^ Edition 4.29 Silberschatz, Galvin and Gagne ©
(^) Thread cancellation is the ability to terminate a thread before it completes execution. This is useful in tasks like timeout handling or stopping unnecessary background computations. (^) Two general approaches or types of Thread Cancellation: (^) Asynchronous cancellation Terminates the thread immediately (unsafe, may leave resources locked). (^) Deferred cancellation Thread periodically checks for a cancellation request and cleans up before exiting (preferred). Operating System Concepts – 9th^ Edition 4.31 Silberschatz, Galvin and Gagne ©
(^) What is Thread-local storage (TLS) (^) TLS allows each thread to have its own copy of data. (^) Unlike global variables (shared across threads), TLS is unique to each thread. (^) Useful when threads need private storage (e.g., per-thread caching, logs).
(^) Windows Threads (^) Linux Threads