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开发者_Python百科 at once if the bank doesn't extend thread?
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).
精彩评论