Skip to content

Commit fed2d47

Browse files
author
Alexander Batashev
authored
[SYCL] Fix library destructor priority value (#3054)
1 parent e2b66ef commit fed2d47

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

sycl/doc/GlobalObjectsInRuntime.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,13 @@ destruction of nested `std::unique_ptr`s.
5757

5858
### Linux
5959

60-
On Linux DPC++ runtime uses `__attribute__((destructor))` property with maximum
61-
possible priority value 65535. This approach does not guarantee, that
62-
`GlobalHandler` destructor is the last thing to run, as user code may contain
63-
a similar function with the same priority value.
60+
On Linux DPC++ runtime uses `__attribute__((destructor))` property with low
61+
priority value 110. This approach does not guarantee, that `GlobalHandler`
62+
destructor is the last thing to run, as user code may contain a similar function
63+
with the same priority value. At the same time, users may specify priorities
64+
within [101, 109] range in order to run destructor after SYCL runtime has been
65+
de-initialized. A destructor without specific priority value is going to be
66+
executed before runtime shutdown mechanisms.
6467

6568
Another approach would be to leak global objects. This would guarantee user,
6669
that global objects live long enough. But some global objects allocate heap

sycl/source/detail/global_handler.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,11 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved) {
154154
return TRUE; // Successful DLL_PROCESS_ATTACH.
155155
}
156156
#else
157-
// Setting maximum priority on destructor ensures it runs after all other global
158-
// destructors.
159-
__attribute__((destructor(65535))) static void syclUnload() { shutdown(); }
157+
// Setting low priority on destructor ensures it runs after all other global
158+
// destructors. Priorities 0-100 are reserved by the compiler. The priority
159+
// value 110 allows SYCL users to run their destructors after runtime library
160+
// deinitialization.
161+
__attribute__((destructor(110))) static void syclUnload() { shutdown(); }
160162
#endif
161163
} // namespace detail
162164
} // namespace sycl

0 commit comments

Comments
 (0)