Browse Source

fix exception segmentfault

tags/v1.2.0-rc1
kswang 5 years ago
parent
commit
375dce4529
2 changed files with 7 additions and 13 deletions
  1. +1
    -2
      mindspore/core/ir/tensor.h
  2. +6
    -11
      mindspore/core/utils/ms_exception.h

+ 1
- 2
mindspore/core/ir/tensor.h View File

@@ -87,10 +87,9 @@ class WaitEvent : public ExceptionListener {
if (!need_wait_) {
return;
}
MsException::Instance().AddExceptionListener(const_cast<WaitEvent *>(this));
MsException::Instance().SetExceptionListener(const_cast<WaitEvent *>(this));
cond_var_.wait(lock, [this] { return !need_wait_; });
MsException::Instance().CheckException();
MsException::Instance().RemoveExceptionListener(const_cast<WaitEvent *>(this));
}

void set_need_wait(bool need_wait) {


+ 6
- 11
mindspore/core/utils/ms_exception.h View File

@@ -34,13 +34,10 @@ class MsException {

void SetException() {
exception_ptr_ = std::current_exception();
if (exception_ptr_ != nullptr) {
for (auto &listener : listeners_) {
if (listener == nullptr) {
continue;
}
listener->OnException();
}
if (exception_ptr_ != nullptr && listener_ != nullptr) {
auto listener = listener_;
listener_ = nullptr;
listener->OnException();
}
}

@@ -52,15 +49,13 @@ class MsException {
}
}

void AddExceptionListener(ExceptionListener *listener) { (void)listeners_.insert(listener); }

void RemoveExceptionListener(ExceptionListener *listener) { (void)listeners_.erase(listener); }
void SetExceptionListener(ExceptionListener *listener) { listener_ = listener; }

private:
MsException() = default;
~MsException() = default;
DISABLE_COPY_AND_ASSIGN(MsException)
std::set<ExceptionListener *> listeners_;
ExceptionListener *listener_{nullptr};
std::exception_ptr exception_ptr_{nullptr};
};
} // namespace mindspore


Loading…
Cancel
Save