Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions sycl/source/detail/global_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,16 @@ void shutdown_early(bool CanJoinThreads = true) {
// upon its release
GlobalHandler::RTGlobalObjHandler->prepareSchedulerToRelease(true);

if (GlobalHandler::RTGlobalObjHandler->MHostTaskThreadPool.Inst) {
// Do not cleanup thread pool on windows during application shutdown.
// Let OS do the cleanup.
bool doThreadPoolCleanup =
GlobalHandler::RTGlobalObjHandler->MHostTaskThreadPool.Inst.get() !=
nullptr;
#ifdef _WIN32
doThreadPoolCleanup &= !CanJoinThreads;
#endif

if (doThreadPoolCleanup) {
Comment thread
uditagarwal97 marked this conversation as resolved.
GlobalHandler::RTGlobalObjHandler->MHostTaskThreadPool.Inst->finishAndWait(
CanJoinThreads);
GlobalHandler::RTGlobalObjHandler->MHostTaskThreadPool.Inst.reset(nullptr);
Expand Down Expand Up @@ -373,8 +382,13 @@ void shutdown_late() {

GlobalHandler::RTGlobalObjHandler->MXPTIRegistry.Inst.reset(nullptr);

// Release the rest of global resources.
#ifndef _WIN32
// Release the rest of global resources. Do not release GlobalHandler
// on Windows and let OS reclaim leaked memory. Releasing GlobalHandler
// on Windows can seg fault if application uses host tasks, as there
// can be a race between host tasks and shutdown.
delete GlobalHandler::RTGlobalObjHandler;
Comment thread
uditagarwal97 marked this conversation as resolved.
#endif
GlobalHandler::RTGlobalObjHandler = nullptr;
}

Expand Down
Loading