HiveBrain v1.2.0
Get Started
← Back to all entries
patternMinor

Increment and Decrement on binary semaphores when their values are $1$ and $0$ respectively?

Submitted by: @import:stackexchange-cs··
0
Viewed 0 times
incrementrespectivelyvaluesarebinarydecrementwhenandsemaphorestheir

Problem

What happens if we increment binary semaphore $x$ when it is equal to $1$.
E.g A process executes $V(x)$ when $x==1$;
What are the possible cases then-

-
Process would be blocked till $x$ becomes $0$. The moment $x$ becomes $0$,it is incremented.

-
Process would be blocked and no present or future changes will be there for $x$. i.e Process assumes as if there was never a $V(x)$.

-
Other. (If there is please mention).

Same query for $P(x)$ operation as well when $x=0$.

  • Actually, Galvin doesn't mention in pseudo code what to do during such condition.



  • Better if Someone could provide standard code for $P(x)$ and $V(x)$... Also, $P$ is wait operation whereas $V$ is signal operation.

Solution

A binary semaphore has the wait() and the signal() method. The one which causes a process to stop is the wait() method, while the one that increments the counter x in the semaphore is signal(). If signal is called when x=1, then the call is just ignored because the queue of blocked processes is empty, and x has already its maximum value. The process that called signal() doesn't block.

Context

StackExchange Computer Science Q#68975, answer score: 4

Revisions (0)

No revisions yet.