From 25cb906403b5bd85c539055947eb1226f5939571 Mon Sep 17 00:00:00 2001 From: "Yang Yang(Tony)" Date: Wed, 24 Jan 2018 19:06:37 -0800 Subject: [PATCH] Fix call once logic (#7839) * fix call once logic * clean up * further clean up --- paddle/platform/call_once.h | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/paddle/platform/call_once.h b/paddle/platform/call_once.h index 00337a7f051..44a4d38f679 100644 --- a/paddle/platform/call_once.h +++ b/paddle/platform/call_once.h @@ -29,20 +29,25 @@ namespace platform { */ template inline void call_once(std::once_flag& flag, Callable&& f, Args&&... args) { - bool good = false; + bool good = true; std::exception ex; - std::call_once(flag, - [&](Args&&... args) { - try { - f(args...); - good = true; - } catch (const std::exception& e) { - ex = e; - } catch (...) { - ex = std::runtime_error("excption caught in call_once"); - } - }, - args...); + try { + std::call_once(flag, + [&](Args&&... args) { + try { + f(args...); + } catch (const std::exception& e) { + ex = e; + good = false; + } catch (...) { + ex = std::runtime_error("excption caught in call_once"); + good = false; + } + }, + args...); + } catch (std::system_error& x) { + throw std::runtime_error("call once failed"); + } if (!good) { throw std::exception(ex); } -- GitLab