Week 5

 Week 5: 

This week we dove into concurrency and threads. I used to think threads were just some background magic that made things run faster. Now I see they are separate paths of execution within the same process that share memory and resources. That’s what makes them powerful and also risky if you are not careful.

We worked with the Threads API. The syntax took some time to get used to but once it clicked, it felt logical. You can create threads, wait for them to finish, and pass in data for them to work on. But because threads share memory, you run into problems if they try to read or write to the same place at the same time.

To prevent that, we use locks. Mutexes were the main tool we used to make sure only one thread touches a critical section of code at a time. Without locks, you get race conditions which are incredibly hard to debug. One thread might change a value halfway through another thread using it and suddenly your program is broken.

We also explored lock-based data structures. Something simple like a linked list becomes much more complex when multiple threads can insert or delete at the same time. You need to protect those operations with locks or everything falls apart.

It was one of the more intense topics so far but also one of the most interesting. I can see why mastering concurrency sets great programmers apart.

Comments

Popular Posts