![]() |
CITS2002 Systems Programming |
← prev | next → | ![]() |
![]() |
|||
Race conditionsMutexes can be used to prevent race conditions. Consider this example of a race condition involving two threads attempting to add funds to a bank account:
In the above example, a mutex variable should be used to lock the balance (variable) while a thread is using this shared resource. Threads owning a mutex typically update global variable(s). When used correctly, the final result (value) is the same as would be observed if all updates were made by a single-threaded program. The variables being updated belong to a critical section. A typical sequence when using a mutex is as follows:
CITS2002 Systems Programming, Lecture 21, p2, 10th October 2023.
|