有没有办法让启动新线程的线程等待到它启动的线程停止?我在考虑使用锁定,但如果线程崩溃,锁将永远不会被释放。
所以当我的程序调用
cTurnCardOvrerConnection thread = new cTurnCardOvrerConnection("thread3", connection, mPlayerList, mPlayersMessages, lBoard);它会一直等到线程结束吗?
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 wait for this thread to terminate.
cTurnCardOvrerConnection thread = new cTurnCardOvrerConnection("thread3", connection, mPlayerList, mPlayersMessages, lBoard);
if ( CheckTimeStamp())
break;
} while( mPlayerList.AllPlayersFinished()==false);发布于 2012-02-16 02:26:02
您可以只使用Thread.join()。
当然,如果主线程只是启动辅助线程,然后等待它完成,那么辅助线程实际上没有任何用处(只需在主线程上完成工作)。
发布于 2012-02-16 02:27:40
尝试使用CountDownLatch。
https://stackoverflow.com/questions/9299043
复制相似问题