chapter 26 - concurrency: an introduction Flashcards
(12 cards)
What is a thread?
function of execution that shares memory with other threads in the same process
runs independently
Why is switching between threads cheaper than switching between processes?
No need to switch page tables
its in the same memory
What does each thread have that helps the OS manage it?
Its own Thread Control Block (TCB)
Two main benefits of using threads?
Parallelism (on multicore systems)
Overlapping I/O with computation (better resource usage)
Why not use processes instead of threads?
Threads are cheaper to create
Threads share memory easily; processes require IPC
What is the role of pthread_create() and pthread_join()?
pthread_create() starts a new thread
pthread_join() waits for a thread to finish
What problem arises when threads access shared variables without protection?
Race conditions → unpredictable and incorrect results
Why is incrementing a variable like counter++ not safe?
It’s made of multiple instructions, and threads can interleave during execution
What is a critical section?
A section of code that accesses shared data
must not be executed by more than one thread at a time
What is mutual exclusion?
A property that ensures only one thread can enter a critical section at a time
What is a race condition?
When two or more threads access shared data at the same time and the result depends on timing
How do we fix race conditions?
By enforcing atomicity in the critical section using synchronization primitives