Week 29 - Concurrency, Multi-Threading, and Synchronization
This week we covered concurrency which refers to the execution of multiple threads or processes in overlapping time periods. Concurrency can optimize performance but it also introduces complexity. Processes with distinct memory spaces and threads that share memory within a process show different concurrency approaches. Threads are lighter in terms of of overhead compared to processes and that makes them ideal for tasks where multiple operations can occur concurrently without the heavy context switching drawbacks. I also learned about synchronization and how it’s critical for ensuring that concurrent operation don’t lead to errors like race conditions.
The lab this week introduced me to multi-threading and thread synchronization by using the pthread library in C. I got to understand the challenges with managing multiple threads and particularly when they share the same memory. I got to run a program that created ten threads, each was attempting to print and iteration number but the behavior was inconsistent because the threads were accessing the same variable without proper synchronization. To fix this I dynamically allocated memory for each thread’s iteration number and made sure that each thread had it’s unique copy.
Comments
Post a Comment