...
This solution uses a mutex to make credits and debits atomic operations. All credits and debits will now effect affect the account balance, so an attacker cannot exploit the race condition to steal money from the bank. Note that the functions used are pthread_*. The standard mutex functions are not thread-safe. The mutex is created with the pthread_mutex functions. In addition, the volatile keyword is used so prefetching will not occur.
...