226k views
0 votes
The following pair of processes share a common variable X :

Process A
int Y;
A1: Y = X*2;
A2: X = Y;

Process B
int Z;
B1: Z = X+1;
B2: X = Z;

X is set to 5 before either process begins execution. As usual, statements within a process are executed sequentially, but statements in process A may execute in any order with respect to statements in process B.
ii) Suppose the programs are modified as follows to use a shared binary semaphore T :
Process A
int Y;
A1: Y = X*2;
A2: X = Y;
signal(T);

Process B
int Z;
B1: wait(T);
B2: Z = X+1;
X = Z;
T is set to 0 before either process begins execution and, as before, X is set to 5.
Now, how many different values of X are possible after both processes finish executing ?
a) one
b) two
c) three
d) four

User Valuator
by
9.1k points

1 Answer

5 votes

Final answer:

When using a shared binary semaphore that forces process B to wait until process A finishes, there is only one possible value of X after both processes finish execution, which is 11.

Step-by-step explanation:

With the implementation of the shared binary semaphore T, process A will complete its execution before process B starts. Initially, X is set to 5. Process A doubles X to 10 and then sets X to this new value. Once process A signals process B (by executing signal(T)), process B begins its execution and increments X by 1, resulting in X being set to 11. Since process A must complete before process B starts, the concurrent processes are effectively serialized, and there is only one possible value of X after both processes finish executing. Therefore, the answer to how many different values of X are possible after both processes finish execution is (a) one.

User Vitrilo
by
7.5k points