Chapter 03 · Watch, then practise
Process Communication and Synchronization
Watch the related lecture, then read the question and answer below.
10 questions · 5 playlist videos. Matches are based on video titles; broader background matches are labeled.
Open the full chapter playlist ↗5 Minutes Engineering · 9:54
5 Minutes Engineering · 9:19
Topic matches: critical sections, race conditions, and semaphores.
1. Critical-section problem and semaphores — 2075 Bhadra
What is the critical-section problem? Why must executing the critical section be mutually exclusive? Describe how semaphores can solve the critical-section problem.
Answer
A critical section is a part of a program that accesses a shared resource, such as memory, a data structure, the CPU, or an I/O resource. More than one process must not execute the critical section at the same time. Processes need a protocol for entering and leaving it so that concurrent changes do not cause a race condition.
Mutual exclusion prevents a second process from entering while the first is inside. Otherwise, changes made by one process can cause errors in another. A semaphore controls entry through wait and releases access through signal. The original pseudocode and accompanying explanation are retained below.
The handwritten explanation repeats process labels in a confusing way. Refer to the original rather than treating those labels as corrected here.


5 Minutes Engineering · 9:54
Covers critical sections and race conditions. No dedicated sleep/wakeup lecture is listed in this chapter playlist.
2. Race conditions, sleep, and wakeup — 2074 Bhadra
What is a race condition? Why are sleep() and wakeup() better than busy waiting?
Answer
A race condition occurs when processes read or write shared data and the final result depends on which process runs when. Busy waiting continually checks a condition, wasting CPU time. With priority scheduling, it can also cause progress problems when the waiting process prevents the process that must release the resource from running. sleep() suspends a process; another process calls wakeup() when it can proceed.
Gate Smashers · 9:09
5 Minutes Engineering · 9:19
Topic matches for test-and-set and semaphore operations. The exact class implementation has not been verified against these videos.
3. TSL and semaphore implementation — 2074 Bhadra
What is TSL? Why is it used? Explain the major operations of a semaphore with a simple implementation as a class.
Answer
TSL means test-and-set lock. It provides synchronization for mutual exclusion. The semaphore operations are wait, used before accessing a resource, and signal, used when the process finishes using it. The source's class implementation is preserved below, including its original notation and incomplete code details.


5 Minutes Engineering · 9:54
Related explanation of critical sections and race conditions; not a verified answer to the question about keeping a critical section short.
4. Keeping the critical section short — 2073 Bhadra
Explain the critical-section problem. Why is it important for a thread to execute its critical section as quickly as possible?
Answer
Only one thread may hold the lock and execute the critical section at a time. Other threads must wait until it releases the lock. Finishing quickly lets those threads proceed sooner. The critical-section definition is given in Question 1.
5 Minutes Engineering · 9:19
Topic match: semaphores. The scanned pseudocode remains the source for the specific implementation.
5. Semaphore definition and operations — 2073 Bhadra
Define a semaphore and explain its major operations, including pseudocode.
Answer
A semaphore is a variable used to solve critical-section and synchronization problems in multiprocessing. The two major operations are wait and signal. Their exact handwritten pseudocode is retained below:


5 Minutes Engineering · 9:54
5 Minutes Engineering · 9:19
Background on mutual exclusion and semaphores. No dedicated producer–consumer or message-passing solution is listed in the supplied playlist.
6. Mutual-exclusion requirements and producer–consumer — 2073 Magh
State the requirements for mutual exclusion. Solve the producer–consumer problem using semaphores and message passing.
Answer
- No two processes may be inside their critical sections simultaneously.
- No assumptions should be made about processor speeds or the number of CPUs.
- A process outside its critical section must not block another process.
- No process should wait forever to enter its critical section.
The semaphore solution is reproduced below. The source does not supply the requested message-passing solution.


Easy Learning with Nisha · 5:15
Topic match: monitors. Coverage of this exact producer–consumer implementation has not been verified.
7. Producer–consumer using monitors — 2072 Ashwin
Solve the producer–consumer problem using monitors.
Answer
The critical operations belong inside a ProducerConsumer monitor, which provides mutual exclusion. A producer or consumer that cannot continue waits on a condition; another operation signals that condition when progress becomes possible. The source uses an item count and conditions for full and empty states. Its partial first attempt and subsequent monitor implementation are both preserved.


5 Minutes Engineering · 11:18
Gate Smashers · 9:09
Topic matches: Peterson’s solution and test-and-set synchronization.
8. Synchronization, Peterson's solution, and TSL — 2072 Magh
Why is synchronization needed? Explain Peterson's solution and TSL as busy-waiting solutions.
Answer
Synchronization coordinates processes using shared resources so that concurrent operations do not leave inconsistent data. Peterson's solution coordinates two processes accessing a shared resource. Each calls enter_region before its critical section and leave_region afterward; entry waits until it is safe to proceed.
TSL copies the old lock value into a register and sets the lock atomically. The process compares the old value with zero and repeats if the lock was already held. On leaving the critical section it releases the lock. The original code and explanations follow.
One source sentence says the lock is set back to 1, while the exit code and later explanation use 0. The inconsistency is retained in the scan.



5 Minutes Engineering · 9:19
Covers semaphore fundamentals only. No dedicated pipe or distributed-semaphore video is listed in the supplied playlist.
9. Pipes and distributed semaphores — 2071 Magh
Why are pipes needed? Define a semaphore and its operations. Can semaphores be used in a distributed system?
Answer
A pipe passes the output of one process to the input of another. The source describes communication between related processes, such as parent and child processes. Semaphore definitions and operations are given in Question 5.
The source says that distributed processors do not share memory and communicate by messages. It then discusses indirectly implementing semaphore-like coordination using message passing.
Source ambiguity: The answer first denies the use of semaphores in distributed systems and later describes a message-based implementation. It does not clearly distinguish a shared-memory semaphore from distributed emulation.

5 Minutes Engineering · 9:54
5 Minutes Engineering · 11:18
Gate Smashers · 9:09
Covers critical sections, Peterson’s solution, and test-and-set. The playlist does not separately cover every approach named in this question.
10. Approaches to mutual exclusion — 2070 Bhadra
Explain approaches that prevent another process from entering its critical section while shared memory is being updated.
Answer
- Disable interrupts: On a single CPU, preventing interrupts stops a process from being switched out during the critical section. Giving user processes this power is unattractive.
- Lock variable: A shared variable indicates whether the critical section is free or occupied. The source presents the 0/1 approach without establishing that the check-and-set operation is atomic.
- Strict alternation: A shared
turnvariable selects which process may enter. The other process busy-waits until the turn changes. - Peterson's solution: Coordinates two processes through shared state; see Question 8.
- TSL: Atomically reads the old lock value and sets the lock; only the process that finds it free enters.
The strict-alternation code and remaining original discussion are preserved below.

