CST 334 Week 6 Journal Entry
Semaphores Semaphores are synchronization primitives that can help manage shared resources. They are variables associated with an underlying counter that can be any integer. Atomic operations can be applied to a semaphore, which will ensure that threads access shared resources in a controlled and orderly manner. Two functions can be used to implement a semaphore: sem_wait and sem_post. The function sem_wait() is called before a critical section of code and decrements the value of a semaphore. If the semaphore is positive, then shared resources are available, and a thread may have access to the critical section. In this case, the semaphore's value is decremented, and the function returns. If it is zero or negative, shared resources are unavailable, and the thread is blocked from the critical section. In this case, the thread has to wait until the semaphore value is positive to access the critical section. The function sem_post() is called at the end of a critical section of c...