synchronization - "S->value <= 0" signal() implementation in semaphore with no busy waiting -
following code of signal()
operation in semaphore no busy waiting (without busy waiting)
implementation of signal()
:
signal (semaphore *s) { s->value++; if (s->value <= 0) { remove process p s->list; wakeup(p); } }
and have question "if-condition".
i think, fact s->value
0 or negative means there no available resource, wakeup()
should not permitted. can see, whenever signal()
operation called, process (which in waiting list) being woken regardless of state of s->value
.
so in opinion, sign of inequality s->value >= 0
natural , makes sense, because s->value > 0
means there available resoures.
is there can explain me in easy english?
you confusing between semaphore's queue , ready queue here. solution meet bounded waiting condition.
when process must wait semaphore s, blocked , put on semaphore’s queue. signal() removes 1 process queue , moves ready queue. because signal() called process has finished critical section. there new process added ready queue.
if add process ready queue when semaphore's value positive doesn't make sense because can use semaphore directly , there, without joining ready queue.
signal (semaphore *s) { s->value++; if (s->value <= 0) { remove process p s->list; wakeup(p); //move 1 process p s->list ready list } }
the negative value indicates number of processes waiting. hope helps.
Comments
Post a Comment