Single and Multithreaded Processes

Benefits of Multithread:
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
Multicore Programming
Concurrency : more than one task making progres
Concurrent execution on single-core system

Parallelism : a system can perform more than one task simultaneously
Parallelism on a multi-core system

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

Amdahl’s Law
Identifies performance gains from adding additional cores to an application that has both serial and parallel components
S is serial portion N is processing cores

Serial portion of an application has disproportionate effect on performance gained by adding additional cores
User Threads and Kernel Threads
User threads : management done by user-level threads library (POSIX Pthreads, Windows threads, Java threads)
Kernel threads : supported by the Kernel (virtually all general purpose operating systems, including: Windows, Linux , Mac OS X, iOS, Android)
Multithreading Models
Many-to-One : One thread blocking causes all to block, Multiple threads may not run in parallel on muticore system because only one may be in kernel at a time

One-to-One : Each user-level thread maps to kernel thread, Creating a user-level thread creates a kernel thread More concurrency than many-to-one

Two-level Model :

Implicit Threading
Creation and management of threads done by compilers and run-time libraries rather than programmers (Thread Pools, Fork-Join, OpenMP)
Thread Pools : Create a number of threads in a pool where they await work
Advantages: : Usually slightly faster to service a request with an existing thread than create a new thread
Allows the number of threads in the application to be bound to the size of the pool
Separating task to be performed from mechanics of creating task allows different strategies for running task
Fork-Join Parallelism : Multiple threads are forked, and then joined

OpenMP : Provides support for parallel programming in shared-memory environments, Create as many threads as there are cores
Signal Handling
Signals are used in UNIX systems to notify a process that a particular event has occurred
Signal is generated by particular event (Keyboard Interrupt, Timer)
Thread Cancellation
Terminating a thread before it has finished
Asynchronous cancellation terminates the target thread immediately
Deferred cancellation allows the target thread to periodically check if it should be cancelled (Cancellation only occurs when thread reaches cancellation point)
Thread-Local Storage
Thread-local storage (TLS) allows each thread to have its own copy of data
Local variables visible only during single function invocation but, TLS visible across function invocations
Similar to static data (TLS is unique to each thread)
'Operating System Design' 카테고리의 다른 글
| Operating System Design - Synchronization Tools (0) | 2021.06.18 |
|---|---|
| Operating System Design - CPU Scheduling (0) | 2021.06.17 |
| Operating System Design - Processes (0) | 2021.06.17 |
| Operating System Design - Operating System Structures (0) | 2021.06.16 |
| Operating System Design - File System Implementation (0) | 2021.06.16 |