diff options
author | Starla Insigna <hatkirby@fourisland.com> | 2009-02-03 17:31:19 -0500 |
---|---|---|
committer | Starla Insigna <hatkirby@fourisland.com> | 2009-02-03 17:31:19 -0500 |
commit | c791c138d4d73b495c8a355ae01bca754e1ce66b (patch) | |
tree | b82e8f2620e00c5a881dc8be0ae5cac6c9d99096 /lib/junit | |
parent | 0a37b19bc1afc4369c7e423bb07f432196273bc9 (diff) | |
download | fourpuzzle-c791c138d4d73b495c8a355ae01bca754e1ce66b.tar.gz fourpuzzle-c791c138d4d73b495c8a355ae01bca754e1ce66b.tar.bz2 fourpuzzle-c791c138d4d73b495c8a355ae01bca754e1ce66b.zip |
Fixed MoveEventThread latch breakage
Previously, MoveEventThread used a CountDownLatch to power it's moveAll() function. However, because CountDownLatch can only count down and not back up, every time a MoveEventThread was spawned, it's static moveEventWait (which was a CountDownLatch) would be re-instantated. If a thread was already waiting on the CountDownLatch, it would be disrupted. This meant that if the first MoveEventThread spawned completed before the rest, the entire program would grind to a halt. This has been fixed by replacing the CountDownLatch with a Semaphore (not exactly what Semaphore is supposed to be used for, but it works). Every time a MoveEventThread is spawned, it acquires a permit from the Semaphone and releases it when it completes. moveAll() then attempts to acquire 100 permits (the Semaphore is initalized to only allow 100 permits), which blocks until all MoveEventThreads have completed. The downside of this is that only 100 MoveEventThreads can execute at once, but it is exceptionally unlikely that such an event will occur. Also, if this does occur, the other MoveEventThreads will simply wait for another to complete and then acquire a permit.
Diffstat (limited to 'lib/junit')
0 files changed, 0 insertions, 0 deletions