Reorganize a bit of code in Game.start() to try to avoid a deadlock (see #23). I think this should fix it but I haven't tested it yet.

This commit is contained in:
Andy Janata 2012-10-17 23:36:37 -07:00
parent 22156e90ac
commit f294f3b64a
1 changed files with 12 additions and 6 deletions

View File

@ -528,19 +528,25 @@ public class Game {
if (state != GameState.LOBBY || !hasBaseDeck()) {
return false;
}
boolean started;
synchronized (players) {
if (players.size() >= 3) {
// Pick a random start judge, though the "next" judge will actually go first.
judgeIndex = (int) (Math.random() * players.size());
blackDeck = new BlackDeck(cardSets);
whiteDeck = new WhiteDeck(cardSets);
startNextRound();
gameManager.broadcastGameListRefresh();
return true;
started = true;
} else {
return false;
started = false;
}
}
if (started) {
// do this stuff outside the players lock; they will lock players again later for much less
// time, and not at the same time as trying to lock users, which has caused deadlocks
blackDeck = new BlackDeck(cardSets);
whiteDeck = new WhiteDeck(cardSets);
startNextRound();
gameManager.broadcastGameListRefresh();
}
return started;
}
public boolean hasBaseDeck() {