From 0df305e226b6858e56ac6f690c735fb219e155f8 Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Mon, 5 Mar 2012 17:15:56 +0000 Subject: Fixed a potential deadlock ( http://forum.mc-server.org/showthread.php?tid=374 ) git-svn-id: http://mc-server.googlecode.com/svn/trunk@369 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/cServer.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'source/cServer.cpp') diff --git a/source/cServer.cpp b/source/cServer.cpp index 3b85a45c4..116861aca 100644 --- a/source/cServer.cpp +++ b/source/cServer.cpp @@ -353,31 +353,36 @@ bool cServer::Tick(float a_Dt) cRoot::Get()->TickWorlds( a_Dt ); // TODO - Maybe give all worlds their own thread? + cClientHandleList RemoveClients; { cCSLock Lock(m_CSClients); for (cClientHandleList::iterator itr = m_Clients.begin(); itr != m_Clients.end();) { if ((*itr)->IsDestroyed()) { - cClientHandle* RemoveMe = *itr; + RemoveClients.push_back(*itr); // Remove the client later, when CS is not held, to avoid deadlock ( http://forum.mc-server.org/showthread.php?tid=374 ) itr = m_Clients.erase(itr); - delete RemoveMe; continue; } (*itr)->Tick(a_Dt); ++itr; - } + } // for itr - m_Clients[] } + for (cClientHandleList::iterator itr = RemoveClients.begin(); itr != RemoveClients.end(); ++itr) + { + delete *itr; + } // for itr - RemoveClients[] cRoot::Get()->GetPluginManager()->Tick( a_Dt ); if( !m_bRestarting ) + { return true; + } else { m_bRestarting = false; m_pState->RestartEvent.Set(); - LOG("<<<<>>>>SIGNALLED SEMAPHORE"); return false; } } -- cgit v1.2.3