From a86327245eea5638b933aec795026699201c19e1 Mon Sep 17 00:00:00 2001 From: Benoit Germain Date: Mon, 28 Apr 2025 11:17:48 +0200 Subject: Minor internal tweaks in shutdown code --- src/lane.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src/lane.cpp') diff --git a/src/lane.cpp b/src/lane.cpp index 5cebdfa..e6ea2e5 100644 --- a/src/lane.cpp +++ b/src/lane.cpp @@ -783,10 +783,14 @@ static void lane_main(Lane* const lane_) if (lane_->selfdestructRemove()) { // check and remove (under lock!) // We're a free-running thread and no-one is there to clean us up. lane_->closeState(); - lane_->U->selfdestructMutex.lock(); - // done with lua_close(), terminal shutdown sequence may proceed - lane_->U->selfdestructingCount.fetch_sub(1, std::memory_order_release); - lane_->U->selfdestructMutex.unlock(); + + // let's try not to crash if the lane didn't terminate gracefully and the Universe met its end + if (!lane_->flaggedAfterUniverseGC.load(std::memory_order_relaxed)) { + lane_->U->selfdestructMutex.lock(); + // done with lua_close(), terminal shutdown sequence may proceed + lane_->U->selfdestructingCount.fetch_sub(1, std::memory_order_release); + lane_->U->selfdestructMutex.unlock(); + } // we destroy ourselves, therefore our thread member too, from inside the thread body // detach so that we don't try to join, as this doesn't seem a good idea -- cgit v1.2.3-55-g6feb