The following two functions P1 and P2 that share a variable B with an ...
There are following ways that concurrent processes can follow.
There are 3 different possible values of B: 2, 3 and 4.
View all questions of this test
The following two functions P1 and P2 that share a variable B with an ...
Explanation:
To determine the number of distinct values that B can take after the execution of the given functions, we need to analyze how the value of B changes in each function and how the two functions interact with each other.
P1 Function:
- C is assigned the value of B - 1 (i.e., C = B -1)
- B is assigned the value of 2 * C (i.e., B = 2*C)
P2 Function:
- D is assigned the value of 2 * B (i.e., D = 2 * B)
- B is assigned the value of D - 1 (i.e., B = D - 1)
Now let's consider the possible values of B after the execution of each function.
Possible values of B after P1:
- If B = 2, then C = 1 and B = 2 * 1 = 2
- If B > 2, then C = B - 1 > 1 and B = 2 * C > 4
- If B < 2,="" then="" c="B" -="" 1="" />< 1="" and="" b="2" *="" c="" />< />
Therefore, after the execution of P1, B can have two possible values: 2 or any value greater than 4.
Possible values of B after P2 (assuming B is initially 2):
- D = 2 * B = 4
- B = D - 1 = 3
Therefore, after the execution of P2, B can have only one possible value: 3.
Possible values of B after both P1 and P2:
- If B = 2, then after P1, B = 2 and after P2, B = 3
- If B > 2, then after P1, B can have any value greater than 4 and after P2, B can have only one possible value, i.e., 3
Therefore, the total number of distinct values that B can possibly take after the execution of both P1 and P2 is 3: 2, 3, and any value greater than 4. Hence, option A is the correct answer.
To make sure you are not studying endlessly, EduRev has designed Computer Science Engineering (CSE) study material, with Structured Courses, Videos, & Test Series. Plus get personalized analysis, doubt solving and improvement plans to achieve a great score in Computer Science Engineering (CSE).