@@ -28,6 +28,7 @@ namespace ze_lib
2828 }
2929 bool delayContextDestruction = false ;
3030 bool loaderTeardownCallbackReceived = false ;
31+ bool loaderTeardownRegistrationEnabled = false ;
3132 void staticLoaderTeardownCallback () {
3233 loaderTeardownCallbackReceived = true ;
3334 }
@@ -370,6 +371,7 @@ namespace ze_lib
370371 GET_FUNCTION_PTR (loader, " zelRegisterTeardownCallback" ));
371372 if (pfnZelRegisterTeardownCallback != nullptr ) {
372373 pfnZelRegisterTeardownCallback (staticLoaderTeardownCallback, &loaderTeardownCallback, &loaderTeardownCallbackIndex);
374+ loaderTeardownRegistrationEnabled = true ;
373375 }
374376 });
375377 #endif
@@ -557,31 +559,33 @@ zelCheckIsLoaderInTearDown() {
557559 if (ze_lib::loaderTeardownCallbackReceived) {
558560 return true ;
559561 }
560- std::promise<int > stabilityPromise;
561- std::future<int > resultFuture = stabilityPromise.get_future ();
562- int result = -1 ;
563- try {
564- // Launch the stability checker thread
565- std::thread stabilityThread (stabilityCheck, std::move (stabilityPromise));
566- result = resultFuture.get (); // Blocks until the result is available
567- stabilityThread.join ();
568- } catch (const std::exception& e) {
569- if (ze_lib::context->debugTraceEnabled ) {
570- std::string message = " Exception caught in parent thread: " + std::string (e.what ());
571- ze_lib::context->debug_trace_message (message, " " );
572- }
573- } catch (...) {
574- if (ze_lib::context->debugTraceEnabled ) {
575- std::string message = " Unknown exception caught in parent thread." ;
576- ze_lib::context->debug_trace_message (message, " " );
562+ if (!ze_lib::loaderTeardownRegistrationEnabled) {
563+ std::promise<int > stabilityPromise;
564+ std::future<int > resultFuture = stabilityPromise.get_future ();
565+ int result = -1 ;
566+ try {
567+ // Launch the stability checker thread
568+ std::thread stabilityThread (stabilityCheck, std::move (stabilityPromise));
569+ result = resultFuture.get (); // Blocks until the result is available
570+ stabilityThread.join ();
571+ } catch (const std::exception& e) {
572+ if (ze_lib::context->debugTraceEnabled ) {
573+ std::string message = " Exception caught in parent thread: " + std::string (e.what ());
574+ ze_lib::context->debug_trace_message (message, " " );
575+ }
576+ } catch (...) {
577+ if (ze_lib::context->debugTraceEnabled ) {
578+ std::string message = " Unknown exception caught in parent thread." ;
579+ ze_lib::context->debug_trace_message (message, " " );
580+ }
577581 }
578- }
579- if (result != ZEL_STABILITY_CHECK_RESULT_SUCCESS ) {
580- if (ze_lib::context->debugTraceEnabled ) {
581- std::string message = " Loader stability check failed with result: " + std::to_string (result);
582- ze_lib::context->debug_trace_message (message, " " );
582+ if (result != ZEL_STABILITY_CHECK_RESULT_SUCCESS ) {
583+ if (ze_lib::context->debugTraceEnabled ) {
584+ std::string message = " Loader stability check failed with result: " + std::to_string (result);
585+ ze_lib::context->debug_trace_message (message, " " );
586+ }
587+ return true ;
583588 }
584- return true ;
585589 }
586590 #endif
587591 return false ;
0 commit comments