1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-24 08:32:34 +02:00

Merge pull request #149 from vmarkovtsev/issue/2306

Remove undefined behavior in requestActionASAP
This commit is contained in:
Alexander Shishkin 2015-12-13 15:31:34 +03:00
commit d9ada3a42f

View File

@ -2705,24 +2705,13 @@ void VCAI::finish()
void VCAI::requestActionASAP(std::function<void()> whatToDo)
{
boost::mutex mutex;
mutex.lock();
boost::thread newThread([&mutex,this,whatToDo]()
boost::thread newThread([this,whatToDo]()
{
setThreadName("VCAI::requestActionASAP::whatToDo");
SET_GLOBAL_STATE(this);
boost::shared_lock<boost::shared_mutex> gsLock(cb->getGsMutex());
// unlock mutex and allow parent function to exit
mutex.unlock();
whatToDo();
});
// wait for mutex to unlock and for thread to initialize properly
mutex.lock();
// unlock mutex - boost dislikes destruction of locked mutexes
mutex.unlock();
}
void VCAI::lostHero(HeroPtr h)