Lecture 4 - Multi-Threading Flashcards
Do most modern applications use multi-threading?
Yes.
What’s the purpose of multiple threads within an application?
Multiple tasks can operate at the same time. (Like chrome browser)
Why use threads rather than create a new process?
Process creating is heavy weight.
Thread creation is super light weight.
Simplify code, increase efficiency.
What’s one advantage of processes over threads?
Processes are more isolated. If they crash, they don’t impact the other processes.
Do threads share the same address space?
Yes.
What do threads share?
The code, the data, and the files.
What do threads not share?
Registers and Stacks.
What are 4 benefits of threads?
- 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
What the challenge that multiprocessor systems put on programmers?
Dividing activities Balance Data slitting Data dependency Testing and debugging
Define Parallelism.
Implies that a system can perform more than one task simultaneously.
Define Concurrency.
Creating the illusion of parallelism with a single processor.
Compare data parallelism vs task 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
Define Amdahl’s Law
Identifies performance gains from adding additional cores to an application that has both serial and parallel portions
speedup <= 1/ (S+ (1-S)/N)
Resulting improvement from an enhancement is “limited” by the fraction of the task that can be improved.
Explain what the Serial part and Parallel part of a process is.
Serial part = Can’t be threaded
Parallel = Can
What’s the difference between User and Kernel threads?
User threads - management done by user-level threads library (GNU Pth), they are super fast.
Kernel threads - Supported by the Kernel (POSIX PThreads)