CST 334 Week 5
The 2 main ideas I learned about this week were concurrency and threads. Threads are units of a single running process, sharing the same address space and data. Using multiple threads helps prevent programs from being blocked by input and output and allows for parallelism, which allows the program to run on multiple processors. Despite its benefits, issues can arise when data becomes inconsistent from multiple threads updating the same data. This dilemma introduces the idea of concurrency, the next major topic I learned about. Within the topic of concurrency, I learned about critical sections of code, which are lines of code that use variables shared by other threads. Next, I learned about race conditions, which is when threads attempt to read or write the same data. This can occur when threads enter the same critical section at the same time and can result in an indeterminate program. An indeterminate program is a program that produces inconsistent results despite having the same input.
To resolve these issues, we learned about what an operating system must do to achieve concurrency within running programs. The first strategy I learned about is the implementation of lock variables. Locks hold information pertaining to its state (whether it is locked or unlocked). Before a critical section of code is entered, lock is given to the thread and it is unlocked once it exits the critical section. Locks provide mutual exclusion, which ensures that only one thread can enter a critical section at once. Another approach to achieving concurrency involves the use of conditional variables. Instead of having a thread spin until it has access to a lock, the thread can sleep while it waits in a queue for a certain condition. Once the appropriate condition is present, the next thread on the queue can be signaled to wake up.
Comments
Post a Comment