1.
Terms related to IPC
- Race condition: Occurs when multiple processes access and manipulate shared data
concurrently, and the outcome depends on the order of execution.
- Critical section: A section of code where shared resources are accessed and only one
process should execute at a time.
- Mutual exclusion: Ensures that only one process can enter the critical section at any given
time.
- Semaphores: A synchronization tool used to control access to shared resources. It can be
binary or counting.
- Bounded waiting: A limit on the number of times a process can be bypassed by others while
waiting to enter the critical section.
- Mutex: A binary semaphore used specifically to achieve mutual exclusion.
- Pipe: A unidirectional communication channel used for inter-process communication.
- Message passing: A method of communication where processes exchange messages to
share information.
2. Bounded Buffer Producer Consumer Problem using Semaphore
- Shared buffer of fixed size.
- Semaphores used: mutex (binary), empty (counting), full (counting).
- Initialization:
- - mutex = 1 (for critical section)
- - empty = N (buffer size)
- - full = 0 (initially no items)
- Producer Process:
- wait(empty);
- wait(mutex);
- // add item to buffer
- signal(mutex);
- signal(full);
- Consumer Process:
- wait(full);
- wait(mutex);
- // remove item from buffer
- signal(mutex);
- signal(empty);
3. Readers and Writers Problem
- Deals with synchronization when multiple readers and writers access shared data.
- Constraints:
- - Multiple readers can read simultaneously.
- - Writers need exclusive access.
- Solution should avoid starvation and ensure fairness.
4. Dining-philosophers Problem
- Five philosophers sit around a table with one fork between each pair.
- Each needs two forks to eat (left and right).
- Problem illustrates deadlock and resource contention.
- Solutions involve limiting resource acquisition or using asymmetric strategies.
5. Deadlock and its Conditions
- Deadlock: A situation where a set of processes are blocked, each waiting for resources held
by the others.
- Conditions for deadlock:
- - Mutual Exclusion
- - Hold and Wait
- - No Preemption
- - Circular Wait
6. Banker's Algorithm for Deadlock Avoidance
- Used to allocate resources safely without causing deadlock.
- Each process declares max resources needed.
- System checks for safe state before allocation.
- Example:
- - Resources: A(10), B(5), C(7)
- - Available: A(3), B(2), C(2)
- - Processes with Allocation and Max requirements
- - System simulates allocation and checks if all processes can finish.
- - If yes, it's a safe state.