-
Notifications
You must be signed in to change notification settings - Fork 38.7k
Initialization: set Boost path locale in main thread #5877
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
Initialization: set Boost path locale in main thread #5877
Conversation
dexX7
commented
Mar 11, 2015
- Boost path seems to use variables which are lazy initialized and not thread safe, and in particular this results in leaks and unexpected behavior, if they are not explicitly initialized by the main thread, because resources may no longer be accessible, if the related thread isn't either. This is basically the underlying issue I'm trying to address, and related issues affected by this are [Qt] Do you want to rebuild the block database now? No -> crash #3136 and libdb_cxx-4.8 leaks? #5380.
- path::imbue(std::locale()) appears to initialize those.
- std::locale() constructs a copy of the current global locale. The global locale is the locale set by a previous call to std::locale::global, or std::locale::classic ("C"), if std::locale::global has not been called. std::locale("") however uses the default environment value.
- Setting locale::global(loc) also sets the C global locale, as if the C library function setlocale was called with LC_ALL, which appears to be more robust, while setenv may not be available in any case.
- locale("") throw exceptions, if invalid environment locales are used, but locale() does only so, if locale::global was set with an invalid locale before, which should not be the case in Bitcoin Core, so I'd assume the old L732 never throws at all.
- I tested it with several build configurations, but I'm not entirely sure, if this is 100 % side effect free.
The path locale is lazy initialized and to avoid deinitialization errors in multithreading environments, it is set explicitly by the main thread.
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.
Are you sure this will still work for boost filesystem v3? I'd assume this #ifdef construction was added for a reason.
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.
Yes, it's actually std::locale("") what raises the exception, which is called from within path::codecvt().
|
Tested ACK, #3136 is fixed with this PR :), great! |
317e66c Initialization: set Boost path locale in main thread (dexX7)
|
Cherry-picked to 0.10 as c9e022b |
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.
This line is the reason for #6078
The path locale is lazy initialized and to avoid deinitialization errors in multithreading environments, it is set explicitly by the main thread. Conflicts: src/util.cpp Rebased-From: 317e66c Github-Pull: bitcoin#5877 (cherry picked from commit c9e022b)
