Two threads each execute counter++ once on a shared counter that starts at 0, with no synchronization. Which final values are possible?
Q2
Of the 20 possible interleavings of two threads each doing load–add–store once, how many give the correct result 2?
Q3
What is a race condition?
Q4
Which requirement of a critical-section solution prevents a thread from waiting forever while others repeatedly enter?
Q5
In Peterson's algorithm, both threads set their flags to true at nearly the same time. Which one enters the critical section first?
Q6
What does compare-and-swap (CAS) do?
Q7
When is a spinlock preferable to a blocking mutex?
Q8
A semaphore has value 0. Process A executes wait(S). With the definition used in this chapter, what happens?
Q9
A mutex semaphore starts at 1. Operations: A wait, B wait, C wait, A signal. What is the semaphore value, and who is running in the critical section?
Q10
A semaphore with initial value 4 protects the 4 GPU slots of the EdgeCampus server. What kind of semaphore is it?
Q11
Thread B must not start processing until thread A has loaded a model. Which initial semaphore value implements this signal (A does signal(S), B does wait(S))?
Q12
In the bounded-buffer solution, what are the initial values of mutex, empty and full for a buffer of size N?
Q13
A producer executes wait(mutex)beforewait(empty). The buffer is full. What can happen?
Q14
In the "readers-first" solution to the readers–writers problem, what is the main risk?
Q15
Five dining philosophers each pick up their left chopstick, then their right one. What can go wrong?
Q16
Why must a thread call wait() inside a while loop that re-checks the condition, rather than an if?
Q17
What does Java's volatile keyword guarantee for a shared variable?
Q18
Which Java class gives a thread-safe counter without using a lock?
Q19
Which Java class is a ready-made bounded buffer for producer–consumer designs?
Q20
What is a key advantage of message passing over shared memory?
Q21
Two EdgeCampus web servers check "is GPU slot 3 free?" and both see "yes", then both book it. What kind of bug is this, and a proper fix?
Q22
Each of two threads increments an unsynchronized shared counter k = 3 times. What is the smallest possible final value?
Q23
Linux kernels often spin briefly, then block when a lock is busy. Why?
Q24
Why does the bounded-buffer solution need both the counting semaphores (empty, full) and the mutex?
Q25
A thread holds a ReentrantLock and an exception is thrown inside the critical section. Where must unlock() be called to avoid other threads waiting forever?
Q26
Kubernetes runs three replicas of its controller manager but only one must act at a time. Which mechanism does it use?
Q27Short answer
Show an interleaving of two threads, each executing x = x + 1 (load, add, store) once with x initially 5, that ends with x = 6, and one that ends with x = 7. Then fix the code in Java in two different ways.
Q28Short answer
Trace a counting semaphore slots = 2 (two GPU slots) for this sequence: A wait, B wait, C wait, D wait, A signal, C signal, B signal, D signal. After each operation give the value, who is waiting (FIFO) and who holds a slot.
Q29Short answer
Explain why the dining-philosophers solution "always pick up the lower-numbered chopstick first" cannot deadlock.
Q30Short answer
EdgeCampus receives AR frames from phones (producers) and processes them on 4 GPU workers (consumers) through a buffer of 64 frames. Design the synchronization (Java or semaphores) and explain what happens when the buffer is full or empty. What policy would you choose for frames when the buffer is full, given that AR needs fresh frames?