Interprocess communication & IPC Problems Flashcards
What are the three main issues related to InterProcess Communication (IPC)?
- Passing information between processes.
- Avoiding conflicts when multiple processes try to access shared resources simultaneously.
- Ensuring proper sequencing when dependencies exist between processes.
What is a race condition?
When two or more processes or threads access shared data, and the final outcome depends on the order in which they execute.
Can occur in both multi-process and multi-threaded systems.
What is mutual exclusion, and why is it important in IPC?
ensures only one process or thread can access a shared resource at a time. –> to prevent race conditions
What is the critical region or critical section?
part of a program where shared memory or resources are accessed, and race conditions can occur.
four conditions required for a good solution to mutual exclusion?
- No two processes may be simultaneously inside their critical regions.
- No assumptions may be made about speeds or the number of CPUs.
- No process running outside its critical region may block any process.
- No process should have to wait forever to enter its critical region.
What is busy waiting?
process continuously checks a condition in a loop until it becomes true. It is used when the waiting time is expected to be short.
Why is disabling interrupts not a suitable solution for mutual exclusion in user processes?
it grants too much power and control over the system.
What is a spin lock?
lock that uses busy waiting. mutual exclusion mechanism where a process repeatedly checks a lock variable until it becomes available.
What are the two operations on semaphores proposed by Dijkstra?
- The two operations on semaphores are down and up (generalizations of sleep and wakeup).
- The down operation checks if the value is greater than 0 and decrements it if so.
- The up operation increments the value of the semaphore.
How does Dijkstra ensure atomicity in semaphore operations?
by making the checking of value, changing it, and possibly going to sleep a single, indivisible atomic action. Once a semaphore operation has started, no other process can access the semaphore until the operation has completed or blocked.
What is the purpose of the mutex semaphore in the producer-consumer problem?
mutex semaphore is used for mutual exclusion to ensure that only one process at a time is reading or writing the buffer and associated variables.
What are mutexes and when are they used?
- simplified version of semaphores used for managing mutual exclusion to a shared resource or piece of code.
- They have two states: unlocked and locked, and only one bit is required to represent them.
- Mutexes are used to control access to critical regions and prevent multiple threads or processes from accessing them simultaneously.
How are mutexes implemented in user space?
- TSL (Test and Set Lock) or XCHG (Exchange) instructions.
What is a futex, and how does it improve performance?
“fast user space mutex” feature in Linux that combines the benefits of spin locks and blocking mechanisms.
When contention occurs, processes are put on a kernel wait queue, and the kernel explicitly unblocks them when the lock is free.
What is the purpose of a futex’s lock variable?
serves as a shared variable among processes or threads to indicate the lock’s state (locked or unlocked).
What is the advantage of using futexes over traditional locking mechanisms?
- improve performance by minimizing switches to the kernel and avoiding busy waiting in low-contention scenarios.
- They combine the efficiency of spin locks with the ability to block processes when contention occurs.
What is message passing in interprocess communication?
Message passing is a method of interprocess communication that uses send and receive primitives to exchange messages between processes.
Messages are sent using the “send” primitive, specifying the destination and message content. They are received using the “receive” primitive, specifying the source (or ANY) and storing the received message.
How is the producer-consumer problem solved using message passing without shared memory?
using message passing by using a fixed number of messages. The producer sends full messages to the consumer, who sends back empty messages. The total number of messages remains constant, ensuring synchronization.
What is a barrier in synchronization mechanisms?
A barrier is a synchronization primitive used for groups of processes. It ensures that no process can proceed to the next phase until all processes have reached the barrier, allowing groups of processes to synchronize.
What is the dining philosophers problem?
The dining philosophers problem is a synchronization problem where five philosophers sit around a table with plates of spaghetti. They alternate between thinking and eating but require two forks to eat. The challenge is to design a program that prevents deadlocks or starvation.