A process consists of an address space, an initial thread, and an initial stack.
Threads are lightweight and share the data segment (initialized, uninitialized data) and the heap.
Access to shared variables needs protections to prevent race conditions.
Synchronization Primitives Include:
Spinlocks
Blocking locks (Mutexes)
Binary semaphores
Monitors
Threads can be categorized as being implemented at the kernel level or user level.
Famous synchronization problems are crucial for understanding fundamental concepts and for job interviews.
Important considerations:
Performance
Interaction with thread priorities
Starvation and Deadlock issues
Synchronization bugs
Heizenbugs (unpredictable behaviors)
Service denial bugs
Blocking Synchronization:
Leads to context switching if a mutex isn't available, freeing the CPU for other tasks.
Spinlock Synchronization:
Can waste CPU resources but is efficient if the mutex is expected to be available soon, avoiding context switch overhead.
Utilizes a combination of spinlock and blocking synchronization:
Start with a spinlock; if the mutex is available, enter the critical section (C.S.).
Spin for a limited time; if the mutex is not available, switch to blocking synchronization.
Relevant primarily for multiprocessor systems.
An issue arising from hardware peculiarities, impacting performance in multi-threading scenarios.
Occurs when a low-priority thread holds a lock that a higher-priority thread needs, leading to a system halt if a medium-priority thread intervenes.
Temporarily boost the priority of the low-priority thread holding the lock to match the higher-priority thread requesting it.
May occur if the synchronization mechanism is improperly implemented, for example, a semaphore implementing LIFO order.
A condition where two or more threads are waiting indefinitely for each other to release resources.
Common in systems employing mutexes.
A classic example illustrates cyclical wait:
Thread 1 requesting a resource held by Thread 2 while Thread 2 waits on Thread 1's resource.
Linear resource ordering
Threads must request resources in a specific order to prevent deadlocks.
While effective, this method can be inflexible and does not scale well.
Allow deadlock to occur and address it through analysis:
Identify and kill a victim process to break the deadlock.
Using a graph to identify deadlocks—the cyclic wait condition indicates a deadlock.
Bugs arising due to inadequate protection of shared variables can lead to unpredictable behaviors.
Conditions where liveness (ongoing progress) is not guaranteed due to unsafe synchronizations.
An informal definition of a transaction: a piece of code that accesses shared resources without interference.
It is critical for the operations to execute atomically.
Example involving bank transactions needs coordinated control over account updates, ensuring atomic outcomes.
Atomicity: All operations must succeed or none at all.
Consistency: Database remains in a consistent state before and after transactions.
Isolation: Each transaction executes as if no other transactions are occurring concurrently.
Durability: Once committed, the transaction's effects should remain despite failures.
Balancing throughput (transactions per second) and latency (time to transaction completion).
Goal: Identify a schedule equivalent to some serial order while maximizing throughput and concurrency.
Finding all possible serializable orders is NP-complete.
Occur when one transaction's abort affects others that have read its temporary values.
Dynamic transaction creation necessitates a reliable scheduling mechanism.
Two-phase locking (acquisition and release phases) is a common solution to avoid issues like cascaded aborts.
Protocol involving coordination across multiple databases where local transactions rely on each other, with a phase for voting to commit or abort.
Multi-database transactions require communication protocols and a commitment to maintain data integrity among various databases.
A network partition can complicate transaction management requiring quorum systems or alternative voting mechanisms.