Skip to content

Instantly share code, notes, and snippets.

@jamesob
Created May 6, 2018 20:20
Show Gist options
  • Save jamesob/a7b05acc4330317f4cf06f505e575eaa to your computer and use it in GitHub Desktop.
Save jamesob/a7b05acc4330317f4cf06f505e575eaa to your computer and use it in GitHub Desktop.
jamesob/threadnames2.2 -> jamesob/threadnames2.3
--- /proc/self/fd/12 2018-05-06 15:36:43.909368915 -0400
+++ /proc/self/fd/13 2018-05-06 15:36:43.901368805 -0400
@@ -342,7 +342,7 @@
peerLogic.reset(new PeerLogicValidation(connman, scheduler));
diff --git a/src/test/threadutil_tests.cpp b/src/test/threadutil_tests.cpp
new file mode 100644
-index 0000000..b3473d1
+index 0000000..bbeb47d
--- /dev/null
+++ b/src/test/threadutil_tests.cpp
@@ -0,0 +1,92 @@
@@ -424,7 +424,7 @@
+ */
+BOOST_AUTO_TEST_CASE(threadutil_test_rename_threaded)
+{
-+ BOOST_CHECK_EQUAL(thread_util::GetInternalName(), thread_util::UNNAMED_THREAD);
++ BOOST_CHECK_EQUAL(thread_util::GetInternalName(), "<unnamed>");
+
+ std::set<std::string> names = RenameEnMasse(100);
+
@@ -440,7 +440,7 @@
+BOOST_AUTO_TEST_SUITE_END()
diff --git a/src/threadutil.cpp b/src/threadutil.cpp
new file mode 100644
-index 0000000..f26b523
+index 0000000..7f0af65
--- /dev/null
+++ b/src/threadutil.cpp
@@ -0,0 +1,213 @@
@@ -589,7 +589,7 @@
+ return static_cast<thread_data_type*>(data)->m_name;
+ }
+ }
-+ return UNNAMED_THREAD;
++ return "<unnamed>";
+}
+
+bool thread_util::SetInternalName(std::string name)
@@ -617,7 +617,7 @@
+
+static inline thread_data_type GetThreadData()
+{
-+ thread_data_type ret{-1, UNNAMED_THREAD};
++ thread_data_type ret{-1, "<unnamed>"};
+ std::thread::id thread_id(std::this_thread::get_id());
+ {
+ std::lock_guard<std::mutex> lock(m_map_mutex);
@@ -659,10 +659,10 @@
+#endif
diff --git a/src/threadutil.h b/src/threadutil.h
new file mode 100644
-index 0000000..9e8d51f
+index 0000000..ecd7121
--- /dev/null
+++ b/src/threadutil.h
-@@ -0,0 +1,59 @@
+@@ -0,0 +1,57 @@
+// Copyright (c) 2018 The Bitcoin Core developers
+// Distributed under the MIT software license, see the accompanying
+// file COPYING or http://www.opensource.org/licenses/mit-license.php.
@@ -686,8 +686,6 @@
+
+namespace thread_util
+{
-+ const std::string UNNAMED_THREAD = "<unnamed>";
-+
+ /**
+ * Rename a thread both in terms of an internal (in-memory) name as well
+ * as its system process name. 

Seeing segfaults on two Travis x86_64 linux jobs which appear to be related to referencing const std::string UNNAMED_THREAD, which is defined in threadutil.h, from the pthreads version of threadutil.cpp:thread_util::GetInternalName().

After some digging, I'm still not sure what's going on here.

Program terminated with signal SIGSEGV, Segmentation fault.
#0  0x00007f8d7462e45b in std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(std::string const&) () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
(gdb) bt
#0  0x00007f8d7462e45b in std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(std::string const&) () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#1  0x00007f8d759b0cdf in thread_util::GetInternalName () at threadutil.cpp:146
#2  0x00007f8d759abb00 in EnterCritical (pszName=pszName@entry=0x7f8d759c0cd9 "ppmutexOpenSSL[i]",
    pszFile=pszFile@entry=0x7f8d759c0cd0 "util.cpp", nLine=nLine@entry=94, cs=0x7f8d75c37288,
    fTry=fTry@entry=false) at sync.cpp:144
#3  0x00007f8d75995ff5 in locking_callback (mode=<optimized out>, i=<optimized out>, file=<optimized out>,
    line=<optimized out>) at util.cpp:94
#4  0x00007f8d74ba23d1 in ?? () from /lib/x86_64-linux-gnu/libcrypto.so.1.0.0
#5  0x00007f8d759a9f87 in RandAddSeed () at random.cpp:133
#6  0x00007f8d75966b24 in __static_initialization_and_destruction_0 (__initialize_p=1, __priority=65535)
    at util.cpp:135
#7  _GLOBAL__sub_I_BITCOIN_CONF_FILENAME () at util.cpp:1001
#8  0x00007f8d759b53cd in __libc_csu_init ()
#9  0x00007f8d73d97ed5 in __libc_start_main (main=0x7f8d759643e0 <main(int, char**)>, argc=3,
    argv=0x7ffe009b6528, init=0x7f8d759b5380 <__libc_csu_init>, fini=<optimized out>,
    rtld_fini=<optimized out>, stack_end=0x7ffe009b6518) at libc-start.c:246
#10 0x00007f8d7596778e in _start ()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment