Threads Synchronization Flashcards
What is a thread?
A lightweight subprocess, shares resources with other threads.
Thread vs process?
Thread is smaller, shares memory; process is isolated.
Java thread states?
New, Runnable, Blocked, Waiting, Timed Waiting, Terminated.
What is the critical section problem?
Multiple threads accessing shared resource concurrently.
Solution requirements for critical section?
Mutual exclusion, progress, bounded waiting.
Define race condition.
Outcome depends on execution order of threads.
What is a semaphore?
A variable used to control access to a resource.
What is a monitor?
High-level construct for synchronisation.
Why are threads called lightweight?
They share resources with other threads, using less overhead.
What is starvation?
A process waits indefinitely due to resource allocation issues.
Define busy waiting.
A thread constantly checks for a condition, wasting CPU.
What’s the difference between mutex and semaphore?
Mutex allows one thread; semaphore can allow multiple (counting).
What is a context switch?
CPU switches from one thread/process to another.