CST 334 Week 5
This week, we explored threading, its benefits, and the potential challenges it introduces. One major issue with threading is that multiple threads running concurrently can interfere with each other, especially when they access shared resources. This interference can lead to race conditions, where the CPU switches between threads in the middle of important calculations, potentially causing incomplete or inconsistent results. To address these issues, we discussed several synchronization mechanisms, including spin locks, test-and-set, compare-and-swap, and ticket locks. These mechanisms ensure that only one thread can access a critical section of code at a time, preventing race conditions and maintaining data integrity. However, each mechanism comes with its own trade-offs. For example, spin locks can waste CPU cycles as a thread waits for access, and they can lead to starvation if threads aren't given a fair chance to acquire the lock. ...