Question

Check My Understanding of semaphores, please!

I understand the idea behind counting semaphores and binary semaphores. However the difference between a spinlock and semaphore implemented with signal() and wait() kind of blend together to me.

For example a spinlock has basically two values (a binary true/false for locked or unlocked). Therefore a spinlock is basically a binary semaphore, correct?

Any process attempting to enter the critical section while another process is inside will be unable to while it's locked, and will spin and continually check the lock status until it is unlocked and then is able to enter and lock it.

A semaphore using a signal() and wait() function essentially add or subtract a value from a variable of some kind. There is a constraint regarding the critical section. It will only be opened when the variable is of some kind of value. An example implementation for a consumer process would be wait(full), then when it's full it executes and at the end it signal(empty). Whereas a producer process may wait(empty) and execute when empty is true, and then when it finishes it signal(full).

What is the difference between wait() and a spinlock that is essentially 'waiting' in a loop?

Was it helpful?

Solution

Unlike semaphores, spinlocks may be used in code that cannot sleep, such as interrupt handlers.

http://www.makelinux.net/ldd3/chp-5-sect-5.shtml

http://www.linuxjournal.com/article/5833

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top