CST 334, Journal Entry Week 5

This week, we learned the fundamentals of locks and concurrency in multithreaded programming. We started by exploring how concurrency allows multiple threads to run simultaneously, which improves performance but introduces challenges when threads access shared resources. To manage this, we studied various locking mechanisms.

We compared spin locks and ticket locks. Spin locks are simple but inefficient under high contention since they waste CPU cycles by continuously checking for lock availability. Ticket locks improve fairness by assigning each thread a “ticket” and serving them in order, reducing the risk of starvation.

We also learned about hardware-level atomic operations, specifically test-and-set and compare-and-swap. These are used to implement low-level synchronization. Compare-and-swap, in particular, allows safe updates without locks by checking whether the data changed before proceeding.

Understanding critical sections and achieving mutual exclusion is key to preventing issues like race conditions, where the outcome of code depends on the order threads execute. These bugs can be hard to detect because they may only appear under specific interleavings of thread execution.

We saw how thread scheduling impacts performance and correctness, and how different interleavings can lead to completely different outcomes. This reinforced the importance of careful synchronization.

Finally, the midterm covered scheduling algorithms such as Round Robin and FIFO, testing our ability to apply these concepts under time pressure. Overall, this week provided a solid foundation in writing safe and efficient concurrent programs by understanding the importance of synchronization and scheduling.


Discussion & Comments