-
-
Notifications
You must be signed in to change notification settings - Fork 244
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
Clean up thread-local error stacks in all threads #4852
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that most of the library changes should go in. I've added comments, but I'm also happy to talk in-person or on a call.
6a59a4d
to
d796ef2
Compare
Vastly simplified this after a discussion with Quincey.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small change, otherwise good :-)
When threadsafety is enabled, threadlocal error stacks in threads that don't call
H5_term_library
do not have any error records stored on them cleaned up properly. This leads to leaked memory and, before the recent changes to H5E, an infinite loop during library close.Set of changes:
This PR was originally much more complex, and the below description is out-of-date.
=====
Fixing this is complicated by the fact that H5TS's cleanup is currently performed after every individual module is terminated. In order for the records to be released properly, H5TS must terminate before H5E and after H5CX, necessitating rearranging the termination order. As a side effect, most H5TS resources that were previously set up and released on a per-process basis (
H5TS_tinfo_mtx_s
,H5TS_api_info_p
,H5TS_thrd_info_key_g
) are now handled per-thread.This is currently a draft PR due to an issue with thread once macros on MacOS builds. The flag the library uses to perform only one initialization of H5TS across all threads,
H5TS_first_thread_init_s
, is not currently cleaned up at library close. If the library is closed and re-opened, the library will see the old value and not properly initialize H5TS.This can be solved on most systems by re-initializing
H5TS_first_init_s = H5TS_ONCE_INITIALIZER
during H5TS termination. However, it appears that on MacOS, thePTHREAD_ONCE_INIT
macro is defined in a manner that causes problems with this approach:My best guess is that MacOS enforces the requirement that
PTHREAD_ONCE_INIT
only be used for static initializations, and this initialization during termination is dynamic. Windows threads have both a static and dynamic once flag initializer (INIT_ONCE_STATIC_INIT
andInitOnceInitialize
) but I haven't been able to find a dynamic counterpart for pthreads.