GATE CS 2020 (Forenoon) — Question 44

Operating Systems (OS)Concurrency & Synchronization (Semaphores, Mutex, Monitors, Locks)MCQ2 marks · −2/3 if wrongMedium

Each of a set of \( n \) processes executes the following code using two semaphores \( a \) and \( b \) initialized to 1 and 0, respectively. Assume that count is a shared variable initialized to 0 and not used in CODE SECTION P.
c
1/* CODE SECTION P */
2wait(a); count=count+1;
3if (count==n) signal(b);
4signal(a); wait(b); signal(b);
5/* CODE SECTION Q */
6
What does the code achieve?
  1. A
    It ensures that no process executes CODE SECTION Q before every process has finished CODE SECTION P.
  2. B
    It ensures that at most two processes are in CODE SECTION Q at any time.
  3. C
    It ensures that all processes execute CODE SECTION P mutually exclusively.
  4. D
    It ensures that at most \( n - 1 \) processes are in CODE SECTION P at any time.
Practise the full 2020-FN paper
Challenge a friend: WhatsApp Telegram
Recommended book · affiliate linkOperating System Concepts (Galvin)Scheduling, synchronisation, deadlocks, memory and file systems.
Practise more on Concurrency & Synchronization (Semaphores, Mutex, Monitors, Locks)Timed, in the real exam interface · free to start

A GATE question every morning

One real past-paper question every morning for your branch, answer hidden until you tap. Free on Telegram.

Join
Stuck? Ask in the student group