operating system - What happens when Binary Semaphore is Signalled twice? ie. s=1;wait(s); signal(s)signal(s); Does s becomes 0 or it remains 1? -
what happens when binary semaphore signalled twice? i.e. suppose s binary semaphore variable s=1
now following--
wait(s),signal(s),signal(s)
does s becomes 0 or remains 1?
the binary semaphore used protect resource, 1 process may access @ time.
this process wait, which, assuming semaphore 1 (resource isn't busy) make semaphore =0.
when process finished resource signal, allowing other processes access resource, making semaphore =1.
there's no reason why process signal twice, nor there reason why other process signal before doing wait (let me know if you've thought of one), 2 successive signals error. if writing os primitive implementation i'd judge better idea leave signal @ 1 put 0 , lock resource out time.
the standard texts on semaphores talk incrementing , decrementing count, that's because it's useful way of thinking counting semaphores. way actual semaphores behave in actual os when they're used in odd way depends on implementation, , not worth examining general theory.
Comments
Post a Comment