diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/universe.cpp | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/src/universe.cpp b/src/universe.cpp index 5fda29a..04db10f 100644 --- a/src/universe.cpp +++ b/src/universe.cpp | |||
| @@ -427,22 +427,24 @@ LUAG_FUNC(universe_gc) | |||
| 427 | kFinalizerRegKey.pushValue(L_); // L_: U finalizer|nil | 427 | kFinalizerRegKey.pushValue(L_); // L_: U finalizer|nil |
| 428 | if (!lua_isnil(L_, -1)) { | 428 | if (!lua_isnil(L_, -1)) { |
| 429 | lua_pushboolean(L_, _allLanesTerminated); // L_: U finalizer bool | 429 | lua_pushboolean(L_, _allLanesTerminated); // L_: U finalizer bool |
| 430 | lua_pcall(L_, 1, 0, 0); // L_: U | 430 | // no protection. Lua rules for errors in finalizers apply normally |
| 431 | // discard any error that might have occured | 431 | lua_call(L_, 1, 1); // L_: U ret|error |
| 432 | lua_settop(L_, 1); | ||
| 433 | } else { | ||
| 434 | lua_pop(L_, 1); // L_: U | ||
| 435 | } | 432 | } |
| 436 | // in case of error, the message is pushed on the stack | 433 | STACK_CHECK(L_, 2); |
| 437 | STACK_CHECK(L_, 1); | 434 | |
| 435 | // if some lanes are still running here, we have no other choice than crashing or freezing and let the client figure out what's wrong | ||
| 436 | bool const _throw{ luaG_tostring(L_, -1) == "throw" }; | ||
| 437 | lua_pop(L_, 1); // L_: U | ||
| 438 | 438 | ||
| 439 | // if some lanes are still running here, we have no other choice than crashing and let the client figure out what's wrong | ||
| 440 | while (_U->selfdestructFirst != SELFDESTRUCT_END) { | 439 | while (_U->selfdestructFirst != SELFDESTRUCT_END) { |
| 441 | throw std::logic_error{ "Some lanes are still running at shutdown" }; | 440 | if (_throw) { |
| 442 | //std::this_thread::yield(); | 441 | throw std::logic_error{ "Some lanes are still running at shutdown" }; |
| 442 | } else { | ||
| 443 | std::this_thread::yield(); | ||
| 444 | } | ||
| 443 | } | 445 | } |
| 444 | 446 | ||
| 445 | // no need to mutex-protect this as all threads in the universe are gone at that point | 447 | // no need to mutex-protect this as all lanes in the universe are gone at that point |
| 446 | if (_U->timerLinda != nullptr) { // test in case some early internal error prevented Lanes from creating the deep timer | 448 | if (_U->timerLinda != nullptr) { // test in case some early internal error prevented Lanes from creating the deep timer |
| 447 | [[maybe_unused]] int const _prev_ref_count{ _U->timerLinda->refcount.fetch_sub(1, std::memory_order_relaxed) }; | 449 | [[maybe_unused]] int const _prev_ref_count{ _U->timerLinda->refcount.fetch_sub(1, std::memory_order_relaxed) }; |
| 448 | LUA_ASSERT(L_, _prev_ref_count == 1); // this should be the last reference | 450 | LUA_ASSERT(L_, _prev_ref_count == 1); // this should be the last reference |
