There's more...

A particular use of semaphores is the mutex. A mutex is nothing but a semaphore with an internal variable initialized to the value of 1, which allows the realization of mutual exclusion in access to data and resources.

Semaphores are still commonly used in programming languages that are multithreaded; however, they have two major problems, which we have discussed, as follows:

  • They do not prevent the possibility of a thread performing more wait operations on the same semaphore. It is very easy to forget to do all the necessary signals in relation to the number of waits performed.
  • You can run into situations of deadlock. For example, a deadlock situation is created when the t1 thread executes a wait on the s1 semaphore, while the t2 thread executes a wait on the thread t1, executes a wait on s2 and t2, and then executes a wait on s1.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset