6th Week: CST 334

Hello everyone,

This week we learned about semaphores. They are a key synchronization tool for managing concurrency in multi threaded programs. A semaphore is a variable that controls access to shared memory through atomic operations. Its main functions are sem_wait(), which decrements and blocks other threads if the semaphore's value is zero, and sem_post(), which increments and unblocks, allowing another thread access to the shared memory. Semaphores, if used with reader/writer locks allow multiple readers while blocking writers. However, they must be used carefully to avoid bugs like deadlocks and race conditions. 

In Lab 6, we used semaphores to solve the producer-consumer problem by signaling between producers and consumers to keep track of the buffer's state when it was empty or full. Correct semaphore use allows threads to work safely within critical sections.

Comments

Popular posts from this blog

CST438 Software Engineering: Week 8 (Final week)

CST438 Software Engineering: Week 1

CST370 Week 5