Deadlock in 5.6

If the program you are writing for question 5.6 is experiencing deadlock (for instance if all three of your customers decide to do a withdrawal when the account balance is zero or all three decide to do a deposit when the balance is MAX) you can do one of two things:

Change your program to eliminate the deadlock. For instance, add code that can cause a customer to change its mind about performing a withdrawal based on the current state of the system. Or add a thread that every now and then deposits money into the account (if the balance is zero) or takes money out of the account (if the balance is max).

Or, you can switch the architecture of your system such that you have at least one thread that always does withdrawals and one that always does deposits alongside the ones that randomly switch between making deposits and making withdrawals.

Its up to you, just make sure your system avoids these deadlock situations!

© Kenneth M. Anderson, 2009