One of the most interesting sections from this week was the topic of semaphores as a synchronization primitive. Semaphores serve as way to help manage concurrency and work very similarly to locks but rather than just letting one thread access critical sections. Semaphores can allow “n” number of threads through. But by setting s semaphore to a value of 1, it can act just like a binary lock. As threads pass through a semaphore, a counter goes ups and down depending on what integer was initialized. As threads use the semaphore, the value decrements and once it reaches 0, no more threads can make use of the critical section. Once a counter reaches zero, it does the “wait()” operation. As threads finish with the critical section, it lets go of the semaphore and increments the value, allowing another thread to make use of its resources. It can serve as great synchronization tool, when two semaphores are used in tandem. Another synchronization primitive we learned about was ...
Comments
Post a Comment