26. Concurrency. An introduction Flashcards
What does thread have its own and what does it share?
Thread has own program counter, stack and private set of registers, but they share a single address space.
Does context switch occur for threads?
Yes, but there is no need in switching page table with threads. The state is also saved to TCB instead of PCB.
How is stack for thread sometimes called?
Thread-local storage.
What is race condition?
It’s when multiple threads are updating the same shared data, but in a way that is not atomic and indeterministic
What is critical section?
Piece of code that accesses a shared variable and can be run only by 1 thread at a time
How to avoid race condition?
With atomic operations which can be atomic either by design (pre-made hardware instruction) or that can be atomic with help of some synchronization primitives