initial value of shared variable X is 10
we have 5 threads of INC()
and
3 threads of DEC()
I1 uses binary semaphore so value of semaphore can be either 1 or 0
now in I1 semaphore is initialized with 1, and we can see when any thread will run (any thread of INC() or DEC() )then firstly wait() is called so semaphore value will become 0 and hence no other thread of INC() or DEC() can run at the same time to access X and once currently running thread is over then only signal() is called so value of semaphore will become 1. so I1 guarantees Mutual Exclusion hence no two threads will be in critical section at a time so,final value of this solution will always be unique no matter in which order you execute it.
so value of V1 = 5 inc and 3 dec in X so V1=5-3+10=12.
In I2 counting semaphore is used that is initialized with 2,
here once any thread is under execution then it will firstly decrement semaphore value by 1 using wait(), now
semaphore has current value as 1 so that means 1 more process can be at critical section at this time,
we want min value here by executing 5 INC() threads and 3 DEC() threads so
(i).take one INC() thread and read current value of X that is 10, now preempt this and and take one DEC() thread and read current value of X that is 10 now semaphore = 0, so next thread will only come if any one of them will be completly executed and call signal() that will make semaphore as 1,
(ii)now just complete INC() thread and call next INC thread and do this untill all 5 INC() thread is over. so now suppose all 5 INC() threads are over and hence current value of X is 15, but when first time we called a DEC() thread it read value 10 so do dec in it and update X so X became 9 similarly execute remaining 2 DEC() threads also one after another and they will make X=7.
So finally V2=7
final answer is V1=12,V2=7.