Exemplo n.º 1
0
 private void liberarCola() {
   // La cola común tiene prioridad, así evitamos el interbloqueo
   if (colaComun.hasQueuedThreads()) {
     colaComun.release();
   } else {
     colaInicial.release();
   }
 }
Exemplo n.º 2
0
 /**
  * Overrides World<T> newGame(char). Shoots a MoveInfo with null piece and null location to the
  * CheckerGame if the game is still running. If the game has ended, directly changes the
  * CheckerGame's game status for CheckerRunner to detect.
  *
  * @param a the new game status
  */
 public void newGame(char a) {
   newGame = a;
   playerPiece = null;
   setPlayerLocation(null);
   if (!lock.hasQueuedThreads()) // if the game has ended
   {
     game.newGame(a);
   }
   super.newGame(); // World's newGame() disposes the frame
 }
 // Synchronizes two threads execution points.
 // Basically any thread could get scheduled to run and
 // it is not possible to know which thread reaches expected
 // execution point. So whichever thread reaches a execution
 // point first wait for the second thread. When the second thread
 // reaches the expected execution point will wake up
 // the thread which is waiting here.
 void stopOrGo() {
   semaphore.acquireUninterruptibly(); // Thread can get blocked.
   if (!waiting) {
     waiting = true;
     // Wait for second thread to enter this method.
     while (!semaphore.hasQueuedThreads()) {
       try {
         Thread.sleep(20);
       } catch (InterruptedException xx) {
       }
     }
     semaphore.release();
   } else {
     waiting = false;
     semaphore.release();
   }
 }