Multiple Choice Questions
1. What is the main purpose of process synchronization?
o A) To ensure processes execute in a random order.
o B) To ensure processes execute independently without interference.
o C) To ensure that concurrent processes do not interfere with each other while
accessing shared resources.
o D) To ensure processes execute as quickly as possible.
Answer: C) To ensure that concurrent processes do not interfere with each other while accessing
shared resources.
2. Which of the following is a classical synchronization problem?
o A) Dining Philosophers
o B) Memory Management
o C) Disk Scheduling
o D) Page Replacement
Answer: A) Dining Philosophers
3. In the context of synchronization, what is a critical section?
o A) A section of code that is executed by only one process at a time.
o B) A section of code that all processes can execute simultaneously.
o C) A section of code that is executed by all processes in the system.
o D) A section of code that handles input/output operations.
Answer: A) A section of code that is executed by only one process at a time.
4. Which of the following is a common synchronization mechanism used to prevent race
conditions?
o A) Mutex
o B) Cache
o C) File System
o D) Buffer
Answer: A) Mutex
5. What does the semaphore 'V' (signal) operation do?
o A) It decrements the semaphore value and may block if the value is less than zero.
o B) It increments the semaphore value and may wake up a blocked process.
o C) It initializes the semaphore value.
o D) It waits for the semaphore to become available.
Answer: B) It increments the semaphore value and may wake up a blocked process.
True/False Questions
1. True or False: A binary semaphore can be used to implement mutual exclusion.
Answer: True
2. True or False: Deadlock can occur when two or more processes are each waiting for the
other to release resources.
Answer: True
3. True or False: In a producer-consumer problem, the producer generates items and places
them in a buffer while the consumer removes items from the buffer.
Answer: True
4. True or False: A process in a critical section can be interrupted by another process if it is
also trying to enter the critical section.
Answer: False
5. True or False: The 'P' (wait) operation on a semaphore decrements its value and may cause
the process to block if the value is zero or negative.
Answer: True
What is the difference between a binary semaphore and a counting semaphore?
Answer: A binary semaphore can only take the values 0 and 1, making it useful for mutual exclusion
(mutex). A counting semaphore can take any non-negative integer value and is used to control access
to a resource pool with a limited number of instances.
Describe the concept of a race condition and provide an example.
Answer: A race condition occurs when the outcome of a process depends on the sequence or timing
of uncontrollable events. For example, if two processes are incrementing a shared counter without
synchronization, they may both read the same value and increment it, leading to incorrect results.
Explain how the 'Test and Set' operation can be used to implement a lock.
Answer: The 'Test and Set' operation atomically tests a value and sets it to a new value if it is
currently a specific old value. It can be used to implement a lock by testing if a lock is free (typically
represented by 0) and setting it to 1 (locked) if it is free. This operation is atomic, preventing race
conditions.
What is a deadlock, and what are the four necessary conditions for it to occur?
Answer: A deadlock is a situation where a set of processes are blocked because each process is
holding a resource and waiting for another resource held by another process. The four necessary
conditions are:
Mutual exclusion
Hold and wait
No preemption
Circular wait
How does a mutex differ from a semaphore in process synchronization?
Answer: A mutex is a synchronization primitive that provides mutual exclusion by allowing only one
process to access a critical section at a time. A semaphore is a more general synchronization
primitive that can be used to manage access to a resource pool and can signal between processes.
Semaphores can be binary (similar to mutexes) or counting, which allows managing multiple
resources.