My program represents a graph. There are villages with roads and gnomes that run along them. The gnomes are threaded. There is a country bank that is not. When a gnome travels along a road it'll pay the toll to the bank. When the roads break, the bank will give up money to repair it. Will I have problems if two gnomes try to pay the bank at once if the bank doesn't extend thread?
A:
The bank does not need to have its own thread, but it can act as a semaphore/lock/monitor for synchronization. The gnomes financial transactions need to be synchronized at the bank (so that, just like in a real bank, they do not pay money at exactly the same time, but one of them has to queue up and wait in line).
Thilo
2010-09-03 04:06:32
Thanks for the help. I'm using Java. I've ended up having the Bank class extend TimerTask and used a Timer to dequeue the Bank's queue every second and the removed int to the Bank's totalMoney. I just need to make sure now that I can add ints to the queue by threaded gnomes safely. Thank you!
Arjun
2010-09-04 18:18:50