17.
Nvidia technical mcq question, verified with a worked answer. Free to practise - no sign-up.
17. Shared variable
A shared variable x is operated on by four concurrent processes A, B, C, D as follows.
Process A reads x from memory, increments by one, stores it to memory, and then terminates.
Process B reads x from memory, increments by two, stores it to memory, and then terminates.
Each of the processes C and D reads x from memory, decrements by two, stores it to memory, and then terminates.
Each process before reading x invokes the P operation (i.e., wait) on a counting semaphore S and invokes the V operation (i.e., signal) on the semaphore S after storing x to memory.
Semaphore S is initialized to two.
What is the maximum possible value of x after all processes complete execution?
Initial value of x is 0.
Pick ONE option
Show answer & explanation
Standard evaluation according to engineering and computational science principles.
Step-by-step Derivation:
Step 1: Analyze problem specification.
Step 2: Derive theoretical solution.
Step 3: Select corresponding answer option.