Computer Science Engineering (CSE) Exam  >  Computer Science Engineering (CSE) Questions  >  Assume that 'C' is counting semaphore... Start Learning for Free
Assume that 'C' is counting semaphore. Consider the following program segment:
C= 10;
P(C);
V(C);
P(C);
P(C);
P(C);
V(C);
P(C);
P(C);
What is the value of 'C' at the end of the above program execution?
  • a)
    2
  • b)
    4
  • c)
    6
  • d)
    10
Correct answer is option 'C'. Can you explain this answer?
Verified Answer
Assume that 'C' is counting semaphore. Consider the following ...
Number of P(C) wait process = 6 i.e. decrement
Number of V(C) signal process = 2 i.e. increment
Therefore value of ‘C’ at the end of program execution
= Initial value - Number of P(C) + Number of V(C)
= 10 - 6 + 2 = 6
View all questions of this test
Most Upvoted Answer
Assume that 'C' is counting semaphore. Consider the following ...
Given:
- C is a counting semaphore
- Program segment: C = 10; P(C); V(C); P(C); P(C); P(C); V(C); P(C); P(C);

To find:
The value of C at the end of the program execution.

Solution:
Let's analyze the program segment step by step to determine the value of C at each step.

Step 1: C = 10;
- Set the initial value of C as 10.

Step 2: P(C);
- P operation (wait operation) on semaphore C.
- If C is greater than 0, decrement C by 1 and continue execution.
- If C is 0, the process will be blocked until another process executes V operation on C.
- In this case, the value of C is 9 after the P operation.

Step 3: V(C);
- V operation (signal operation) on semaphore C.
- Increment C by 1.
- The value of C becomes 10 after the V operation.

Step 4: P(C);
- P operation on C.
- The value of C becomes 9 after the P operation.

Step 5: P(C);
- P operation on C.
- The value of C becomes 8 after the P operation.

Step 6: P(C);
- P operation on C.
- The value of C becomes 7 after the P operation.

Step 7: V(C);
- V operation on C.
- The value of C becomes 8 after the V operation.

Step 8: P(C);
- P operation on C.
- The value of C becomes 7 after the P operation.

Step 9: P(C);
- P operation on C.
- The value of C becomes 6 after the P operation.

Final value of C:
After the execution of the program segment, the value of C is 6.

Answer:
Therefore, the correct answer is option c) 6.
Explore Courses for Computer Science Engineering (CSE) exam

Similar Computer Science Engineering (CSE) Doubts

Assume that 'C' is counting semaphore. Consider the following program segment:C= 10;P(C);V(C);P(C);P(C);P(C);V(C);P(C);P(C);What is the value of 'C' at the end of the above program execution?a)2b)4c)6d)10Correct answer is option 'C'. Can you explain this answer?
Question Description
Assume that 'C' is counting semaphore. Consider the following program segment:C= 10;P(C);V(C);P(C);P(C);P(C);V(C);P(C);P(C);What is the value of 'C' at the end of the above program execution?a)2b)4c)6d)10Correct answer is option 'C'. Can you explain this answer? for Computer Science Engineering (CSE) 2025 is part of Computer Science Engineering (CSE) preparation. The Question and answers have been prepared according to the Computer Science Engineering (CSE) exam syllabus. Information about Assume that 'C' is counting semaphore. Consider the following program segment:C= 10;P(C);V(C);P(C);P(C);P(C);V(C);P(C);P(C);What is the value of 'C' at the end of the above program execution?a)2b)4c)6d)10Correct answer is option 'C'. Can you explain this answer? covers all topics & solutions for Computer Science Engineering (CSE) 2025 Exam. Find important definitions, questions, meanings, examples, exercises and tests below for Assume that 'C' is counting semaphore. Consider the following program segment:C= 10;P(C);V(C);P(C);P(C);P(C);V(C);P(C);P(C);What is the value of 'C' at the end of the above program execution?a)2b)4c)6d)10Correct answer is option 'C'. Can you explain this answer?.
Solutions for Assume that 'C' is counting semaphore. Consider the following program segment:C= 10;P(C);V(C);P(C);P(C);P(C);V(C);P(C);P(C);What is the value of 'C' at the end of the above program execution?a)2b)4c)6d)10Correct answer is option 'C'. Can you explain this answer? in English & in Hindi are available as part of our courses for Computer Science Engineering (CSE). Download more important topics, notes, lectures and mock test series for Computer Science Engineering (CSE) Exam by signing up for free.
Here you can find the meaning of Assume that 'C' is counting semaphore. Consider the following program segment:C= 10;P(C);V(C);P(C);P(C);P(C);V(C);P(C);P(C);What is the value of 'C' at the end of the above program execution?a)2b)4c)6d)10Correct answer is option 'C'. Can you explain this answer? defined & explained in the simplest way possible. Besides giving the explanation of Assume that 'C' is counting semaphore. Consider the following program segment:C= 10;P(C);V(C);P(C);P(C);P(C);V(C);P(C);P(C);What is the value of 'C' at the end of the above program execution?a)2b)4c)6d)10Correct answer is option 'C'. Can you explain this answer?, a detailed solution for Assume that 'C' is counting semaphore. Consider the following program segment:C= 10;P(C);V(C);P(C);P(C);P(C);V(C);P(C);P(C);What is the value of 'C' at the end of the above program execution?a)2b)4c)6d)10Correct answer is option 'C'. Can you explain this answer? has been provided alongside types of Assume that 'C' is counting semaphore. Consider the following program segment:C= 10;P(C);V(C);P(C);P(C);P(C);V(C);P(C);P(C);What is the value of 'C' at the end of the above program execution?a)2b)4c)6d)10Correct answer is option 'C'. Can you explain this answer? theory, EduRev gives you an ample number of questions to practice Assume that 'C' is counting semaphore. Consider the following program segment:C= 10;P(C);V(C);P(C);P(C);P(C);V(C);P(C);P(C);What is the value of 'C' at the end of the above program execution?a)2b)4c)6d)10Correct answer is option 'C'. Can you explain this answer? tests, examples and also practice Computer Science Engineering (CSE) tests.
Explore Courses for Computer Science Engineering (CSE) exam
Signup to solve all Doubts
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev