Chapter 4 - Threads & Concurrency Flashcards
What does a thread represent?
A thread represents a basic unit of CPU utilization, and threads belonging to the same process share many of the process resources, including code and data.
What are the four primary benefits to multithreaded applications?
- responsiveness
- resource sharing
- economy
- scalability
What are concurrency and parallelism and when are they possible?
Concurrency exists when multiple threads are making progress, whereas parallelism exists when multiple threads are making progress simlutaneously. On a system with a single CPU, only concurrency is possible;
What does data parallelism distrubute?
Data parallelism distributes subsets of the same data across different computing cores and performs the same operation on each core. Task parallelism distrubtes not data but tasks across multiple cores. Each task is running a unique operation.
What creates user-level threads?
User applications create user-level threads, which must ultimately be mapped to kernel threads to execute on a CPU. The many-to-one model maps many user-level threads to one kernel thread. Other approaches include the one-to-one and many-to-many models.
What does a thread library provide?
A thread library provides an API for creating and managing threads. Three common thread libraries include Windows, Pthreads, and Java threading. Windows is for the Windows system only, while Pthreads is available for POSIX-compatible systems such as UNIX, Linux, and macOS. Java threads will run on any system that supports a Java virtual machine.
What does implicit threading involve?
Implicit threading involves identifying tasks – not threads – and allowing languages or API frameworks to create and manage threads. There are several approaches to implicit threading, including thread pools, fork-join frameworks, and Grand Central Dispatch.
How can threads be terminated?
Threads may be terminated using either asynchronous or deferred cancellation. Asynchronous cancellation stops a thread immediately, even if it is in the middle of performing an update. Deferred cancellation informs a thread that it should terminate but allows the thread to terminate in an orderly fashion. In most circumstances, deferred cancellation is preferred to asynchronous termination.
How are processes and threads referred to in Linux?
Unlike many other operating systems, Linux does not distinguish between processes and threads; instead, it refers to each as a task. The linux clone() system call can be used to create tasks that behave either more like processes or more like threads.