Wednesday, 7 October 2015

Binary Semaphore or Reentrant lock

Prefer a binary Semaphore or Reentrant lock

There is no real reason ever to have a binary semaphore as everything that a binary semaphore can do that can also done by a ReentrantLock.

Avoid semaphore because:

As binary semaphores are not reentrant, we cannot acquire a binary semaphore second time in a same thread. It will lead to a deadlock (deadlocking thread with itself!) and you may need some means of already mentioned deadlock recovery.

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...