开发者

extend Thread and calling non Thread methods

开发者 https://www.devze.com 2023-01-15 03:43 出处:网络
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

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).

0

精彩评论

暂无评论...
验证码 换一张
取 消