mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 06:58:57 +01:00
util: avoid using thread_local variable that has a destructor
Store the thread name in a `thread_local` variable of type `char[]` instead of `std::string`. This avoids calling the destructor when the thread exits. This is a workaround for https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=278701 For type-safety, return `std::string` from `util::ThreadGetInternalName()` instead of `char[]`. As a side effect of this change, we no longer store a reference to a `thread_local` variable in `CLockLocation`. This was dangerous because if the thread quits while the reference still exists (in the global variable `lock_data`, see inside `GetLockData()`) then the reference will become dangling.
This commit is contained in:
@@ -37,11 +37,11 @@ struct CLockLocation {
|
||||
const char* pszFile,
|
||||
int nLine,
|
||||
bool fTryIn,
|
||||
const std::string& thread_name)
|
||||
std::string&& thread_name)
|
||||
: fTry(fTryIn),
|
||||
mutexName(pszName),
|
||||
sourceFile(pszFile),
|
||||
m_thread_name(thread_name),
|
||||
m_thread_name(std::move(thread_name)),
|
||||
sourceLine(nLine) {}
|
||||
|
||||
std::string ToString() const
|
||||
@@ -60,7 +60,7 @@ private:
|
||||
bool fTry;
|
||||
std::string mutexName;
|
||||
std::string sourceFile;
|
||||
const std::string& m_thread_name;
|
||||
const std::string m_thread_name;
|
||||
int sourceLine;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user