1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Merge pull request #597 from dydzio0614/AiInterruptFix

Ensure no freeze on AI interruption
This commit is contained in:
Alexander Shishkin 2019-06-03 16:53:35 +03:00 committed by GitHub
commit b16af04a09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 0 deletions

View File

@ -2447,6 +2447,8 @@ void VCAI::recruitHero(const CGTownInstance * t, bool throwing)
void VCAI::finish()
{
//we want to lock to avoid multiple threads from calling makingTurn->join() at same time
boost::lock_guard<boost::mutex> multipleCleanupGuard(turnInterruptionMutex);
if(makingTurn)
{
makingTurn->interrupt();

View File

@ -112,6 +112,9 @@ public:
std::shared_ptr<CCallback> myCb;
std::unique_ptr<boost::thread> makingTurn;
private:
boost::mutex turnInterruptionMutex;
public:
ObjectInstanceID selectedObject;
AIhelper * ah;

View File

@ -167,6 +167,8 @@ static_assert(sizeof(bool) == 1, "Bool needs to be 1 byte in size.");
# define BOOST_THREAD_VERSION 3
#endif
#define BOOST_THREAD_DONT_PROVIDE_THREAD_DESTRUCTOR_CALLS_TERMINATE_IF_JOINABLE 1
//need to link boost thread dynamically to avoid https://stackoverflow.com/questions/35978572/boost-thread-interupt-does-not-work-when-crossing-a-dll-boundary
#define BOOST_THREAD_USE_DLL //for example VCAI::finish() may freeze on thread join after interrupt when linking this statically
#define BOOST_BIND_NO_PLACEHOLDERS
#if defined(_MSC_VER) && (_MSC_VER == 1900 || _MSC_VER == 1910 || _MSC_VER == 1911)