Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[umf] create/destroy memory tracker in lib ctor/dtor #693

Merged
merged 1 commit into from
Jul 7, 2023

Conversation

igchor
Copy link
Member

@igchor igchor commented Jul 5, 2023

instead of using a static variable.

In C++ no guarantee is made for initialization order of static variables across translation units.

This is problematic when an application (e.g. SYCL) wants to do some cleanup in it's library destructor. Such application might want to specify priority for it's destructor (to make sure it's executed before any other library desturctor) but it doesn't seem to work for static variables.

Copy link
Contributor

@kswiecicki kswiecicki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It fixed the issue with memory tracker destruction in llvm.

instead of relying on global variable init/destruction on
linux and on windows (when building UMF as a shared lib).

In C++ no guarantee is made for initialization order of
static variables across translation units.

This is problematic when an application (e.g. SYCL) wants
to do some cleanup in it's library destructor. Such application
might want to specify priority for it's destructor (to make sure
it's executed before any other library desturctor) but it doesn't
seem to work for static variables.

Memory tracker is still created as a global object when building
UMF as a static lib on Windows - there is no
__attribute__((destructor)) equivalent that would work for static
library.
@igchor igchor marked this pull request as ready for review July 6, 2023 18:42
umf_memory_tracker_handle_t umfMemoryTrackerGet(void) {
static umf_memory_tracker_t tracker;
return &tracker;
#if defined(_WIN32) && defined(UMF_SHARED_LIBRARY)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's fine for now while we have only one global, but eventually we might want to consolidate this somehow and create windows/linux abstractions (like in the loader).

@pbalcer pbalcer merged commit a4bf2a5 into oneapi-src:main Jul 7, 2023
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants