Multithreaded Programming Flashcards
(32 cards)
What are the basic components of a thread?
Basic components include:
* Thread ID
* Program counter
* Register set
* Stack
* Thread-specific data
Threads are lightweight processes that share the same resources of the parent process.
What is the difference between threads and processes?
Threads share resources of the same process, while processes have separate memory spaces.
This makes thread creation lighter and faster compared to process creation.
What are the benefits of multithreaded applications?
- Responsiveness
- Resource Sharing
- Economy
- Scalability
Responsiveness is especially important for user interfaces, allowing continued execution even if part of the process is blocked.
What challenges do programmers face in multicore programming?
- Dividing activities
- Balance
- Data splitting
- Data dependency
- Testing and debugging
These challenges arise due to the need for parallel execution across multiple cores.
Define concurrency.
Concurrency supports more than one task making progress simultaneously.
It can occur on a single-core system where the scheduler provides the illusion of parallelism.
What is parallelism?
Parallelism implies a system can perform more than one task simultaneously.
This typically occurs on multicore systems.
What is data parallelism?
Data parallelism distributes subsets of the same data across multiple cores, performing the same operation on each.
This is effective for operations that can be parallelized across large datasets.
What does Amdahl’s Law state?
Amdahl’s Law identifies performance gains from adding additional cores to an application that has both serial and parallel components.
It shows that the serial portion of an application has a disproportionate effect on performance.
What are user threads?
User threads are managed by user-level thread libraries.
Examples include POSIX Pthreads, Windows threads, and Java threads.
What are kernel threads?
Kernel threads are supported by the operating system kernel.
They are used in virtually all general-purpose operating systems like Windows and Linux.
What is the many-to-one threading model?
In the many-to-one model, many user-level threads are mapped to a single kernel thread.
A blocking user thread causes all threads to block, limiting parallel execution.
What is the one-to-one threading model?
In the one-to-one model, each user-level thread maps to a kernel thread.
This model allows more concurrency than many-to-one but may restrict the number of threads per process.
What characterizes the many-to-many threading model?
The many-to-many model allows many user-level threads to be mapped to many kernel threads.
This provides flexibility and is used in some operating systems, such as Windows with the ThreadFiber package.
What is a thread library?
A thread library provides an API for creating and managing threads.
It can be implemented in user space or as a kernel-level library.
What are the semantics of the fork() system call in threading?
The behavior of fork() varies; it may duplicate only the calling thread or all threads in some UNIX systems.
The exec() call generally replaces the running process, including all threads.
What is signal handling in multithreaded applications?
Signal handling can be synchronous or asynchronous, with threads specifying which signals to accept or block.
UNIX allows a thread to define its signal handlers, while Windows uses asynchronous procedure calls (APCs).
Fill in the blank: A thread pool is a _______ for managing multiple threads efficiently.
collection of pre-initialized threads.
True or False: In the one-to-one threading model, creating a user-level thread creates a kernel thread.
True
What is thread-local storage?
Thread-local storage allows threads to maintain their own data without conflicts.
This is crucial for data that must not be shared between threads.
What is the role of scheduler activations in threading?
Scheduler activations provide a mechanism to efficiently manage kernel threads and user threads.
They help in balancing the load between user-level threads and kernel scheduling.
Where should a signal be delivered for multi-threaded processes?
Deliver the signal to the thread to which the signal applies
Other options include delivering to every thread, certain threads, or assigning a specific thread to receive all signals.
What is thread cancellation?
Terminating a thread before it has finished
The thread to be canceled is the target thread.
What are the two general approaches for thread cancellation?
- Asynchronous cancellation terminates the target thread immediately
- Deferred cancellation allows the target thread to periodically check if it should be cancelled
What happens when a thread cancellation request is invoked?
Cancellation depends on thread state
If cancellation is disabled, it remains pending until enabled.