Week 2 Flashcards
IPC Challenges:
Processes must exchange information, avoid conflicts, and handle dependencies, often over shared memory.
IPC Mechanisms:
Processes require synchronization for safe communication. The OS offers features to handle shared resources safely, such as using shell pipelines for chaining commands (e.g., history | grep export).
Shared Memory Communication:
Example: Multiple processes printing files by adding them to a spooler directory managed by a printer daemon. The OS uses variables like next_free_slot to avoid overwriting data, ensuring organized access to shared memory.
Critical Region and Mutual Exclusion:
Critical Region: Code accessing shared memory, where only one process is allowed at a time to prevent conflicts.
Mutual Exclusion Techniques:
Disable Interrupts: Useful in single-CPU systems where process disables interrupts to maintain exclusive access.
Lock Variables: Creates a “lock” that processes check before entering the critical region.
Strict Alternation: Uses a “spin lock” where processes take turns accessing the critical region.
Producer-Consumer Model:
Often used in distributed systems (e.g., Apache Kafka). A producer and consumer share a fixed-size buffer. If the buffer is full, the producer waits (sleeps) until there is space—an example of the “sleep and wakeup” IPC model.
Semaphores:
Semaphores are similar to mutexes but act as a queue for waiting processes. A semaphore is an integer counting waiting processes. When it reaches 0, additional processes are put to sleep until woken up by another process incrementing the semaphore.
Reader-Writer Problem:
Example: Databases with simultaneous read and write access, like an airline reservation system.
Solution:
Readers: Use a semaphore (db) and a counter (rc) to control entry to the critical section. Multiple readers can access simultaneously if no writer is active.
Writers: Writers require exclusive access through the same semaphore, allowing only one writer at a time in the critical section.
Problem: A writer may face indefinite delays if a continuous stream of readers enters first, causing writer starvation.
Mutex (Mutual Exclusion):
Function: Simplifies exclusive access, especially useful in user-space threads. A shared variable with “locked” or “unlocked” states prevents concurrent access.
Thread Yield: In user-space, a locked mutex allows a thread to yield execution, letting other threads run while waiting to recheck access.
Monitors:
Purpose: A higher-level synchronization structure containing procedures, variables, and data structures. Only one process can be active in a monitor at a time.
Automatic Mutual Exclusion: The compiler ensures that calls to monitor procedures don’t cause race conditions, simplifying synchronization.
Message Passing:
Function: Allows processes to communicate through system calls (e.g., send and receive).
Challenges: Distributed systems face issues like lost messages, naming, authentication, and message retransmission with sequence numbers.
Conditional Variables:
Purpose: Used in synchronization to block threads until specific conditions are met.
Use with Mutexes: A thread locks a mutex and waits on a condition variable if the condition isn’t met; other threads signal or broadcast to wake them.
Signal Loss: Condition variables don’t store memory, so if a signal is sent without waiting threads, it’s lost. Careful programming is required to ensure no signals are missed