As we discussed in previous post, Spinlock is spinning lock, the same way Semaphore is sleeping lock.
So think of a scenario in which a task want to acquire a semaphore which is not available, so it will go to sleep and semaphore will put it on a wait queue. Once this semaphore becomes available, scheduler will invoke any of the task on this waitqueue.
Properties:
1. As the task holding semaphore can sleep, it is best suitable for the task which runs for longer duration.
2. As the task holding semaphore can sleep, it can only be used in Process Context.
3. Task cant hold a spinlock if it wants to acquire a semaphore. Because task might want to sleep while waiting for semaphore, but this will cause processor to sleep for infinte time(if it is holding spinlock), as there is no one to wake it up.
So think of a scenario in which a task want to acquire a semaphore which is not available, so it will go to sleep and semaphore will put it on a wait queue. Once this semaphore becomes available, scheduler will invoke any of the task on this waitqueue.
Properties:
1. As the task holding semaphore can sleep, it is best suitable for the task which runs for longer duration.
2. As the task holding semaphore can sleep, it can only be used in Process Context.
3. Task cant hold a spinlock if it wants to acquire a semaphore. Because task might want to sleep while waiting for semaphore, but this will cause processor to sleep for infinte time(if it is holding spinlock), as there is no one to wake it up.
No comments:
Post a Comment