CS FundamentalsHardGATE CS
Semaphores x = 0 and y = 0. P1: print('A'); signal(x); wait(y); print('B'). P2: print('C'); signal(y); wait(x); print('D'). Which of the strings ACBD, CADB, ABCD, CDAB can be printed?
- A. All four
- B. ACBD, CADB and ABCD only
- C. Only ACBD
- D. ACBD and CADB only
Correct answer: D. ACBD and CADB only
This is a rendezvous: B needs C (y) and D needs A (x), so both A and C must precede both B and D. ACBD and CADB satisfy this; ABCD prints B before C and CDAB prints D before A. All possible outputs: ACBD, ACDB, CABD, CADB.
More Operating Systems questions
- Shared int x = 0. Two threads each execute x = x + 1; TWICE, without synchronisation; each statement is a load into a private register, an…
- Shared int x = 1. Thread T1 executes x = x 2; and T2 executes x = x + 3; concurrently with no locking (each is load, compute, store). How…
- Which property does Peterson's algorithm guarantee for two processes, assuming loads and stores are atomic and NOT reordered?
- A test-and-set spinlock: while (TestAndSet(&lock)); / CS / lock = false;. Which requirement of the critical-section problem does it NOT…
- A semaphore S is initialised to 3. The operations wait(S) ×6, signal(S) ×2, wait(S) ×1 are issued in that order by different processes…
- Binary semaphore mutex = 1 protects a counter. A programmer mistakenly writes signal(mutex); / critical section / wait(mutex); in every…