- 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 #3136 and #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.
Initialization: set Boost path locale in main thread #5877
pull dexX7 wants to merge 1 commits into bitcoin:master from dexX7:test-path-multithread-deinit-guard changing 1 files +9 −9-
dexX7 commented at 3:34 pm on March 11, 2015: contributor
-
Initialization: set Boost path locale in main thread
The path locale is lazy initialized and to avoid deinitialization errors in multithreading environments, it is set explicitly by the main thread.
-
laanwj added the label Improvement on Mar 11, 2015
-
in src/util.cpp: in 317e66c741
722@@ -723,18 +723,18 @@ void RenameThread(const char* name) 723 724 void SetupEnvironment() 725 { 726-#ifndef WIN32 727- try 728- { 729-#if BOOST_FILESYSTEM_VERSION == 3 730- boost::filesystem::path::codecvt(); // Raises runtime error if current locale is invalid
laanwj commented at 4:42 pm on March 11, 2015:Are you sure this will still work for boost filesystem v3? I’d assume this#ifdef
construction was added for a reason.
dexX7 commented at 1:38 pm on March 12, 2015:Yes, it’s actuallystd::locale("")
what raises the exception, which is called from withinpath::codecvt()
.jonasschnelli commented at 3:01 pm on March 21, 2015: contributorlaanwj merged this on Mar 24, 2015laanwj closed this on Mar 24, 2015
laanwj referenced this in commit 28cc24f961 on Mar 24, 2015laanwj commented at 7:46 am on March 24, 2015: memberCherry-picked to 0.10 as c9e022b7eee9f77cd33b333d6ff52f711d3bc989laanwj referenced this in commit c9e022b7ee on Mar 24, 2015in src/util.cpp: in 317e66c741
741+ std::locale::global(std::locale("C")); 742 } 743 #endif 744+ // The path locale is lazy initialized and to avoid deinitialization errors 745+ // in multithreading environments, it is set explicitly by the main thread. 746+ boost::filesystem::path::imbue(std::locale());
jonasschnelli commented at 11:28 am on May 1, 2015:This line is the reason for #6078reddink referenced this in commit 66c4b44c75 on May 27, 2020DrahtBot locked this on Sep 8, 2021
dexX7 laanwj jonasschnelli DiapoloLabels
Refactoring
github-metadata-mirror
This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-12-18 18:12 UTC
This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-12-18 18:12 UTC
This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me
More mirrored repositories can be found on mirror.b10c.me