• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests

GATE | CSE 2023 | Question 39

Consider the two functions incr and decr shown below.

incr(){	                                     decr(){
wait(s);	                                 wait(s);
X = X+1;	                                 X = X-1;
signal(s);	                                 signal(s);
}                                            }

There are 5 threads each invoking incr once, and 3 threads each invoking decor once, on the same shared variable X. The initial value of X is 10.

Suppose there are two implementations of the semaphore s, as follows:

I-1: s is a binary semaphore initialized to 1.
I-2: s is a counting semaphore initialized to 2.

Let V1, and V2 be the values of X at the end of the execution of all the threads with implementations I-1, and y

I-2, respectively.

Which one of the following choices corresponds to the minimum possible values of V1, V2, respectively?

(A)

15,7

(B)

7,7

(C)

12,7

(D)

12,8

Answer

Please comment below if you find anything wrong in the above post
Feeling lost in the world of random DSA topics, wasting time without progress? It's time for a change! Join our DSA course, where we'll guide you on an exciting journey to master DSA efficiently and on schedule.
Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 geeks!

Last Updated :
Share your thoughts in the comments