Computer Science BS Journal (CST334) : Week 6

 This week in CST334 our lectures covered: Bounded Buffer Coding, Semaphores, Synchronization Barriers. In this learning journal I'll write and explanation/what I think to be the most important bits of each subject. 

Bounded Buffer Coding (Producer-Consumer Problem)

A bounded buffer is a fixed-size storage used in the classic Producer-Consumer problem. Producers add items to the buffer, and consumers remove them. Coordination is required to avoid overfilling or emptying the buffer.

Key Takeaways:

  • Solves coordination between multiple producers and consumers.

  • Needs synchronization to prevent buffer overflows (producer) and underflows (consumer).

  • Typically implemented using mutexes (for mutual exclusion) and semaphores (to count available slots/items).

  • Ensures safe access to shared resources in concurrent environments.

Semaphores

A semaphore is a synchronization primitive used to control access to a shared resource. It uses a counter and two atomic operations: wait (P) and signal (V).

Key Takeaways:

  • Counting semaphore tracks multiple resources; binary semaphore (mutex) is for exclusive access.

  • wait() decreases the counter; blocks if counter < 0.

  • signal() increases the counter; wakes up a waiting thread.

  • Useful in implementing resource limits (like bounded buffer) and preventing race conditions.

Synchronization Barriers

A synchronization barrier is a mechanism where threads wait until all participating threads reach a certain point before any can proceed.

Key Takeaways:

  • Ensures that all threads are "in sync" at a specific stage.

  • Used in parallel algorithms that proceed in phases.

  • Typically used in scientific computing or data-parallel operations.

  • Helps prevent premature execution of later stages of computation.

Comments

Popular posts from this blog

Computer Science BS Journal: Week 4

Computer Science BS Journal (CST363) : Week 7

Computer Science BS Journal (CST363) : Week 2