In: Computer Science
There are two different ways to implement semaphore, one is to use busy waiting and the other is to use block and wakeup. What are the differences between the two implementation schemes? In what scenario does the busy-waiting semaphore have a better performance than the block-and-wakeup semaphore?
ANSWERS :
ANS 1. Differences between the two implementation schemes :
* Busy waiting --
# It is also called as spin waiting.
# In this a process does not do anything unless it gets permission to enter the critical section, but only keeps on checkng the condition and matching it with the condition to gain access to the critical section.
# It watses a lot of CPU cycles.
* Block and wake up --
# In this if a process waits to access the critical section to start execution it is blocked and then put into a queue. Where at regular intervals one process is removed and that process is being moved to ready queue.
# The increement and decreement of the semaphore is responsible in blocking the process and in controlling the entry to the critical section.
In following scenario the busy-waiting semaphore have a better performance than the block-and wakeup semaphore :
* If the the resources of the processors are not needed for any other tasks.
* When the wait time is less than the Scheduling overhead.
* Can be preffered in case of parallel program sometimes.