Podcast
Questions and Answers
What is the fundamental unit of CPU utilization in a multithreaded computer system?
What is the fundamental unit of CPU utilization in a multithreaded computer system?
Thread
What are the benefits of multithreading? Select all that apply.
What are the benefits of multithreading? Select all that apply.
- Resource Sharing (correct)
- Responsiveness (correct)
- Scalability (correct)
- Economy (correct)
Thread Creation is considered heavier than Process Creation.
Thread Creation is considered heavier than Process Creation.
False (B)
___ executes independent tasks in the same instant of time.
___ executes independent tasks in the same instant of time.
Match the following thread models with their descriptions:
Match the following thread models with their descriptions:
Flashcards are hidden until you start studying
Study Notes
Thread and Process
- A thread is a path of execution within a process, also known as a lightweight process.
- The idea is to achieve parallelism by dividing processes into multiple threads.
- Threads are the fundamental unit of CPU utilization and are the basis for multithreaded computer systems.
- They run within an application.
Multithreaded Systems
- Most modern applications, including kernels, are multithreaded.
- Process creation is heavy-weight, while thread creation is light-weight.
- Simple code is more efficient in multithreaded systems.
- Multiple tasks can be performed simultaneously, such as updating a display, fetching data, and spell checking.
Benefits of Multithreading
- Responsiveness: allows continued execution if part of a process is blocked, which is important for user interfaces.
- Resource sharing: threads share resources of a process easier than shared memory or message passing.
- Economy: thread creation has lower overhead than context switching.
- Scalability: processes can take advantage of multiprocessor architectures.
Multicore Programming
- Helps create concurrent systems for deployment on multicore processor and multiprocessor systems.
- A single processor with multiple execution cores in one chip.
Challenges of Multithreading
- Dividing activities into threads.
- Balancing the load between threads.
- Data splitting and dependency.
- Testing and debugging.
Parallelism and Concurrency
- Parallelism: performs more than one task simultaneously, executing independent tasks at the same instant of time.
- Concurrency: supports more than one task making progress, with multiple tasks executed in an overlapping time period.
- There are two types of parallelism: data parallelism and task parallelism.
Thread Libraries
- User threads: management is done by a user-level thread library.
- Kernel threads: supported by the kernel of the OS.
- Three primary thread libraries: POSIX/Pthreads, Java Threads, and Win32 Threads.
Multithreading Models
- One to one: each user-level thread maps to a kernel thread.
- Many to one: many user-level threads map to a single kernel thread.
- Many to many: many user-level threads map to many kernel threads.
- Two-level model: similar to many to many, but allows a user thread to be bound to a kernel thread.
Thread Library Implementation
- Two primary ways to implement: library entirely in user space, or kernel-level library supported by the OS.
- PThreads: POSIX Portable Operating System Interface, common in UNIX OS (Solaris, Linux, Mac OS X).
- IEEE 1003.1c: POSIX standard API for creating and synchronizing threads.
- Win32: kernel-level, windows.h.
- Java Threads: managed by the JVM, implemented using the threads provided by the underlying OS.
Creating Threads in Java
- Two methods: derive a new class from a thread class and override its run() method, or define a class and implement a runnable interface.
- Implicit threading: use of libraries or other language support to hide the management of threads, such as OpenMP.
Thread Pools
- Create a number of threads in a pool where they await work.
- Faster to service a request with an existing thread than creating a new thread.
- Allows the number of threads to be bound to the size of the pool.
OpenMP and Grand Central Dispatch
- OpenMP: set of compiler directives for C, C++, or FORTRAN, provides support for parallel programming in shared memory environments.
- Grand Central Dispatch: Apple technology for Mac OS X and iOS Operating Systems, extensions to C, C++, languages, API, and runtime library.
Threading Issues
- Semantics of fork() and exec().
- Signal handling (synchronous and asynchronous).
- Thread cancellation (asynchronous and deferred).
- Thread-local storage: allows each thread to have its own copy of data.
- Scheduler activations: both M:M and two-level models require communication to maintain the appropriate number of kernel threads allocated to the application.
Operating System Examples
- Windows Threads: implements 1 to 1 mapping, kernel-level.
- Linux Threads: refer to them as tasks, created through clone(), with flags controlling behavior.
- struct task_struct points to process data structures (shared or unique).
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.