OA. free
Free
Qualcomm Embedded Systems & Hardware Embedded Systems & Hardware Medium

Consider the process constructs given below: A: B: Processes A and B both can execute their...

Qualcomm technical mcq question, verified with a worked answer. Free to practise - no sign-up.

Consider the process constructs given below:

A:

while (a)
{
    t = true;
    while (t = false)
    {
        //Critical Sect    }
}

B:

while (t)
{
    q = true;
    while (q != false)
    {
        //Critical Sect    }
}

Processes A and B both can execute their critical sections with mutual exclusion.

Choose one option.
Show answer & explanation
Answer: C. Process B cannot access its critical section if process B executes first.

Process A uses the assignment operator (t = false), which always evaluates to false, causing the inner while loop to never execute—a logic error that prevents entry to the critical section. Process B uses the comparison operator (q != false), which correctly checks if q is not false; however, if B executes first, it sets q = true and then loops infinitely on while (q != false) because q never becomes false. Only option C accurately identifies this deadlock scenario where Process B cannot proceed if it starts first.

Step-by-step Derivation:
Analysis of Process A:

  • Outer loop: while (a) — condition depends on external variable 'a'
  • Sets t = true
  • Inner loop: while (t = false) — This is an ASSIGNMENT, not a comparison
    • The expression (t = false) always evaluates to false (the assigned value)
    • Loop condition is false, so the inner loop never executes
    • Critical section is NEVER reached
    • Result: Deadlock/starvation

Analysis of Process B:

  • Outer loop: while (t) — depends on external variable 't'
  • Sets q = true
  • Inner loop: while (q != false) — This is a COMPARISON
    • Condition is true (q is true, so q != false is true)
    • Loop should execute, but q is never modified inside
    • Result: Infinite loop if B executes first
    • Result: If B starts, it gets stuck and never exits, blocking A

Evaluation of Options:

  • A: FALSE — Neither process can guarantee mutual exclusion due to logic errors
  • B: FALSE — Process A cannot even enter its critical section (due to assignment operator bug), so the scenario is moot
  • C: TRUE — Process B enters an infinite loop if it executes first (q = true, then while(q != false) loops forever)
  • D: FALSE — Process A specifically can never access (it's a logic bug), but this phrasing suggests neither can, which is imprecise