Consider the two functions incr and decr below.
Five threads each call
incr once and three threads each call
decr once on the same shared variable \(X\) (initially \(10\)).
There are two semaphore implementations:
I-1: \(s\) is a binary semaphore initialized to \(1\).
I-2: \(s\) is a counting semaphore initialized to \(2\).
Let \(V_1, V_2\) be the values of \(X\) at the end of all threads for I-1 and I-2, respectively.
Which choice gives the
minimum possible values of \(V_1, V_2\)?
incr(){
wait(s);
X = X + 1;
signal(s);
}
decr(){
wait(s);
X = X - 1;
signal(s);
}