From 4c5732c6426cc272b380e3e93b5192e67f118c7d Mon Sep 17 00:00:00 2001 From: sunsuodong Date: Mon, 15 Nov 2021 19:56:06 -0800 Subject: [PATCH] fix vs run bug --- include/api/status.h | 2 +- mindspore/core/mindrt/include/actor/actor.h | 4 ---- mindspore/core/mindrt/src/actor/actor.cc | 12 ++++++++++++ 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/include/api/status.h b/include/api/status.h index e59f16e4fea..d01a40755ca 100644 --- a/include/api/status.h +++ b/include/api/status.h @@ -121,7 +121,7 @@ class MS_API Status { inline std::string GetErrDescription() const; inline std::string SetErrDescription(const std::string &err_description); - friend std::ostream &operator<<(std::ostream &os, const Status &s); + MS_API friend std::ostream &operator<<(std::ostream &os, const Status &s); bool operator==(const Status &other) const; bool operator==(enum StatusCode other_code) const; diff --git a/mindspore/core/mindrt/include/actor/actor.h b/mindspore/core/mindrt/include/actor/actor.h index ace51ed0693..b25f1afbde5 100644 --- a/mindspore/core/mindrt/include/actor/actor.h +++ b/mindspore/core/mindrt/include/actor/actor.h @@ -205,11 +205,7 @@ class ActorBase { AID id; std::map actionFunctions; -#ifdef _MSC_VER - std::recursive_mutex waiterLock; -#else std::mutex waiterLock; -#endif std::string msgRecords[MAX_ACTOR_RECORD_SIZE]; uint32_t recordNextPoint = 0; diff --git a/mindspore/core/mindrt/src/actor/actor.cc b/mindspore/core/mindrt/src/actor/actor.cc index aa559078d76..76571288f8f 100644 --- a/mindspore/core/mindrt/src/actor/actor.cc +++ b/mindspore/core/mindrt/src/actor/actor.cc @@ -40,8 +40,20 @@ void ActorBase::Await() { // lock here or at spawn(). and unlock here or at worker(). wait for the worker to finish. MS_LOG(DEBUG) << "ACTOR is waiting for terminate to finish. a=" << actorName.c_str(); +#ifdef _MSC_VER +#define TRY_LOCK_INTERVAL 10 + while (true) { + if (waiterLock.try_lock()) { + waiterLock.unlock(); + break; + } else { + std::this_thread::sleep_for(std::chrono::milliseconds(TRY_LOCK_INTERVAL)); + } + } +#else waiterLock.lock(); waiterLock.unlock(); +#endif // mailbox's hook may hold the actor reference, we need explicitly free the mailbox to avoid the memory leak. the // details can refer to the comments in ActorMgr::Spawn