Java thread timing issue in my card game server
<p>I have a timing issue and I don't know how to fix it.</p>

<p>In my second loop, Display card, it loops and each connection starts a class called  <code>cLookAtCardConnection</code>.  This class will sometimes set the flag <code>mPlayerList.GetNextFlag()</code>, thus causing the loop to exit and the program goes to the first loop, Turn card over, which calls the class <code>cLookAtCardConnection</code></p>

<p>The problem is that after <code>mPlayerList.GetNextFlag()</code> is set, the next couple connections are still in the same loop and call the class  <code>cLookAtCardConnection</code> instead of (exiting?) the loop when the flag is set and going into the loop that calls <code>cLookAtCardConnection</code>.</p>

<p>Why is there a delay in the loop exiting after the flag has been set?</p>

<pre><code>while( lBoard.Next()==true)
        {

        mPlayerList.Next();

        // inner loop wait for all players
        /////////////////////////////////////////////////////////////////////////////
        // turn one card over
         mPlayerList.WaitForAllPlayers();
            do
            {
                    do{
                        r=GetClient();
                        switch(r)
                        {
                        case 0: return; // exitvon a very bad error
                        }
                    } while(r==2);// loop if it was a timeout               
                    cTurnCardOvrerConnection thread = new cLookAtCardConnection("thread3", connection, mPlayerList, mPlayersMessages, lBoard);

                } while( mPlayerList.AllPlayersFinished()==false);// end while

            //////////////////////////////////////////////////////////////////////////
            // Display card -LOOK AT CARD
            mPlayerList.ClearNextFlag();
             mPlayerList.WaitForAllPlayers();
            do
            {
                System.out.println(Thread.currentThread()+": Display card \r");
                    do{
                        r=GetClient();
                        switch(r)
                        {
                        case 0: return; // exitvon a very bad error
                        }
                    } while(r==2);// loop if it was a timeout       
                    cLookAtCardConnection thread = new cLookAtCardConnection("thread3", connection, mPlayerList, mPlayersMessages, lBoard);

// after this flag is set the next couple connectons are still in this loop???      
            } while( mPlayerList.GetNextFlag()==false);// end while

        } // reloop game board
    } // loop forever   
    //      System.out.println("--------- Eit player loop ------------------- \r"); 

        } catch(IOException ec)
        {
            System.out.println(ec.getMessage());            
        }



      } // end run

} // end of class
</code></pre>
