CST 334 - Week 6

Concurrency with Multithreading

This week was a continuation on Locking, Threads, and Concurrency. The major topic for this week was the inclusion of Semaphores. Semaphores are provided by the OS as a way to support both locks and signaling in one type of object. A Sepmaphore (or "sem") contains an integer value that can be incremented and decremented more than once, as well as a conditional variable that can be used for signaling other threads, giving it more flexiblity than a simple lock.

Once a thread needs to enter a critical section, it requests a semaphore by calling "wait", this will decrement the semaphore. As long as the sem is greater than 0, the OS will allow the thread to continue. However, if a thread has already requested the sem, the second thread will continue to wait. The more threads attempt to use the sem, the further away the value gets from 0, and all subsequent threads are put into a queue. The value gets incremented once a thread releases the sem with "post". Once a post is done, the sem value is incremented and a signal is sent based on the sem's conditional variable. This allows it to accomplish the work of a lock and a conditional variable at once.

Comments

Popular Posts