The following "parallel" code is given which contains two value entry commands (':') in variables. The two commands are
Posted: Thu May 05, 2022 1:10 pm
The following "parallel" code is given which contains two value entry commands (':') in variables. The two commands are labeled E1 and E2, respectively. Assume that A and B are integer variables that initially have the values 8 and 3, respectively cobegin E1: A = A - : B; E2: B = B A; coend Give the final values that variables A and B can receive after the execution of the parallel code, taking into account all possible scenarios of execution (interleavings) of the commands in the following cases: a). In the case that each command is not executed individually-indivisibly but in two steps. More specifically: Command E1: A: = A - B is executed in two steps: • E1.1: T1: = A - B; /* the value of the difference A - B is initially calculated and entered in a register T1 * / • E1.2: A: = T1; /* then the value of register T1 is entered in variable A * / Command E2: B: = B-A is executed in two steps: • E2.1: T2: = B - A; /* the value of the difference B - A is initially calculated and entered in a T2 register */ • E2.2: B: = T2; /* then the value of register T2 is entered in variable B */ b). In case each command is not executed individually-indivisibly (but in two steps, as described above in sub- question [a]), and in addition for synchronization purposes a s1 semaphore (which is initially set to value 1) is used as follows: cobegin begin P(s1); E1: A A - B; V(s1); end begin P(s1); E2: BB- A; V(s1); end coend c). In the case where each command is not executed individually-indivisibly (but in two steps, as described above in sub-question [a]), and in addition two semaphores s1 and s2 are used for synchronization purposes (which are initialized to values 1 and 0, respectively) as following: cobegin begin P (s1); E1: A: = A - B; V (s2); end begin P (s2); E2: B: = B - A; V (s1); end coend