Skip to content

Conversation

@dexX7
Copy link
Contributor

@dexX7 dexX7 commented Mar 11, 2015

  1. 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.
  2. path::imbue(std::locale()) appears to initialize those.
  3. 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.
  4. 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.
  5. 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.
  6. 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.
Copy link
Member

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.

Copy link
Contributor Author

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().

@laanwj
Copy link
Member

laanwj commented Mar 20, 2015

Tested ACK (tested that SetupEnvironment still does what it should, not tested that #3136 / #5380 don't occur anymore - can you try @Diapolo?).

@jonasschnelli
Copy link
Contributor

Tested. ACK.
#3136 is fixed with this PR.
#5380 still occurs (OSX 10.10). I don't see a relation between this PR and #5380. Multiple leaks detected (could be not real leaks because of BDB style of handling memory):
bildschirmfoto 2015-03-21 um 15 57 10

@Diapolo
Copy link

Diapolo commented Mar 21, 2015

Tested ACK, #3136 is fixed with this PR :), great!

@laanwj laanwj merged commit 317e66c into bitcoin:master Mar 24, 2015
laanwj added a commit that referenced this pull request Mar 24, 2015
317e66c Initialization: set Boost path locale in main thread (dexX7)
@laanwj
Copy link
Member

laanwj commented Mar 24, 2015

Cherry-picked to 0.10 as c9e022b

laanwj pushed a commit that referenced this pull request Mar 24, 2015
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: #5877
Copy link
Contributor

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

reddink pushed a commit to reddcoin-project/reddcoin-3.10 that referenced this pull request May 27, 2020
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)
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants