CST 334 - Week 6
This week we studied semaphores as well as possible problems with concurrency. Semaphores are objects with an integer variable that assist in synchronizing a program with multiple threads. They are similar to using locks and conditions in the sense that they help to control access to shared resources such as files or memory. The integer the semaphore carries can either be zero, which means the process that called for the semaphore is blocked, or it can be another integer greater than zero, which means the process now has access to the resource it is requesting.
Concurrency bugs are another topic studied this week. These are bugs that can arise with multi-threaded programs or running multiple applications at once. An example of a concurrency bug is an atomicity violation bug. This type of bug occurs when two or more threads access a value at the same time or before the previous thread has a chance to finish with the variable. As you can probably tell this will definitely eventually cause undesired outcomes. The first thread could start first and do something such as update the stored value. At the same time, another thread can start that access the same value as thread one and produce an output dependent on what the value is. If the first thread was not finished with the value before the second thread accesses it then an undesired output is quite possible.
Comments
Post a Comment