Skip to content
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

Remove boost threads #269

Merged
merged 20 commits into from
Jul 5, 2023
Merged

Remove boost threads #269

merged 20 commits into from
Jul 5, 2023

Conversation

Naviabheeman
Copy link
Contributor

change boost::threads to std::threads

some changes made by bitcoin are ported to tapyrus
18264 - remove boost::chrono

18710 - local thread pool to CCheckQueue

21016 - remove boost::thread_group usage

src/index/txindex.cpp Outdated Show resolved Hide resolved
src/rpc/blockchain.cpp Outdated Show resolved Hide resolved
src/wallet/db.cpp Outdated Show resolved Hide resolved
src/addrman.cpp Outdated Show resolved Hide resolved
src/checkqueue.h Outdated Show resolved Hide resolved
src/checkqueue.h Outdated Show resolved Hide resolved
src/test/checkqueue_tests.cpp Show resolved Hide resolved
src/test/test_tapyrus.cpp Outdated Show resolved Hide resolved
test/lint/pending-lint-includes.sh Show resolved Hide resolved
@azuchi
Copy link
Contributor

azuchi commented Jun 21, 2023

In src/wallet/walletdb.cpp,

catch (const boost::thread_interrupted&) {

still remain.

@azuchi
Copy link
Contributor

azuchi commented Jun 21, 2023

In configure.ac

boost::this_thread::sleep(boost::posix_time::milliseconds(0));
boost::this_thread::sleep_for(boost::chrono::milliseconds(0));
CPPFLAGS="$CPPFLAGS -D_MT -DWIN32 -D_WINDOWS -DBOOST_THREAD_USE_LIB"

still remain.

@azuchi
Copy link
Contributor

azuchi commented Jun 21, 2023

build-aux/m4/ax_boost_thread.m4 and build-aux/m4/ax_boost_chrono.m4 still need?

@azuchi
Copy link
Contributor

azuchi commented Jun 21, 2023

In depends/packages/boost.mk still remain boost and chrono.

$(package)_config_libraries=chrono,filesystem,system,thread,test

@Naviabheeman
Copy link
Contributor Author

This PR contains only c++ files. All build related changes are in PR#270.

@Naviabheeman
Copy link
Contributor Author

This seems to causing failures in the CI

/bin/bash: line 1: 25441 Aborted                 (core dumped) test/test_tapyrus -l test_suite -t "`cat test/checkqueue_tests.cpp 

Please do not merge yet. Let me investigate.

@Naviabheeman
Copy link
Contributor Author

I'm seeing that master/control thread of CCheckQueue and CCheckQueueControl hangs, waiting for the worker threads to signal. But the worker threads are also waiting for work. This could be because of the implementation of lock and condition variable. It should be tested further. the
tapyrusd, bench_tapyrus and test_tapyrus all hang because of this

Master call stack

(gdb) bt
#0  0x00007ff5dc1b9ad3 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib/x86_64-linux-gnu/libpthread.so.0
#1  0x00007ff5dab9c8bc in std::condition_variable::wait(std::unique_lock<std::mutex>&) () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#2  0x0000555f03154342 in CCheckQueue<checkqueue_tests::FakeCheckCheckCompletion>::Loop (this=this@entry=0x555f058f05f0, fMaster=fMaster@entry=true) at ./checkqueue.h:100
#3  0x0000555f0314c1c1 in CCheckQueue<checkqueue_tests::FakeCheckCheckCompletion>::Wait (this=<optimized out>) at ./checkqueue.h:163
#4  CCheckQueueControl<checkqueue_tests::FakeCheckCheckCompletion>::Wait (this=<synthetic pointer>) at ./checkqueue.h:224
#5  checkqueue_tests::Correct_Queue_range (range=std::vector of length 1, capacity 1 = {...}) at test/checkqueue_tests.cpp:166
#6  0x0000555f0314ca28 in checkqueue_tests::test_CheckQueue_Correct_Zero::test_method (this=this@entry=0x7ffe26214a50) at test/checkqueue_tests.cpp:180
#7  0x0000555f0314cd33 in checkqueue_tests::test_CheckQueue_Correct_Zero_invoker () at test/checkqueue_tests.cpp:176
#8  0x00007ff5db8e82ce in boost::detail::function::function_obj_invoker0<boost::detail::forward, int>::invoke(boost::detail::function::function_buffer&) ()
   from /usr/lib/x86_64-linux-gnu/libboost_unit_test_framework.so.1.65.1

Worker call stack

(gdb) bt
#0  0x00007ff5dc1b9ad3 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib/x86_64-linux-gnu/libpthread.so.0
#1  0x00007ff5dab9c8bc in std::condition_variable::wait(std::unique_lock<std::mutex>&) () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#2  0x0000555f0341e382 in CCheckQueue<CScriptCheck>::Loop (this=<optimized out>, fMaster=fMaster@entry=false) at ./checkqueue.h:100
#3  0x0000555f0341e9e4 in CCheckQueue<CScriptCheck>::CCheckQueue(unsigned int, int)::{lambda()#1}::operator()() const (__closure=<optimized out>) at ./checkqueue.h:148
#4  std::__invoke_impl<void, CCheckQueue<CScriptCheck>::CCheckQueue(unsigned int, int)::{lambda()#1}>(std::__invoke_other, CCheckQueue<CScriptCheck>::CCheckQueue(unsigned int, int)::{lambda()#1}&&) (__f=...) at /usr/include/c++/7/bits/invoke.h:60
#5  std::__invoke<CCheckQueue<CScriptCheck>::CCheckQueue(unsigned int, int)::{lambda()#1}>(std::__invoke_result&&, (CCheckQueue<CScriptCheck>::CCheckQueue(unsigned int, int)::{lambda()#1}&&)...) (__fn=...) at /usr/include/c++/7/bits/invoke.h:95
#6  std::thread::_Invoker<std::tuple<CCheckQueue<CScriptCheck>::CCheckQueue(unsigned int, int)::{lambda()#1}> >::_M_invoke<0ul>(std::_Index_tuple<0ul>) (
    this=<optimized out>) at /usr/include/c++/7/thread:234
    ```

initialize m_request_stop variable in the constructor and handle  empty queue length separately
@Naviabheeman Naviabheeman requested a review from azuchi July 3, 2023 17:22
@Naviabheeman
Copy link
Contributor Author

Thread deadlock is resolved by today's changes.

src/bench/checkqueue.cpp Show resolved Hide resolved
src/checkqueue.h Outdated Show resolved Hide resolved
src/util.cpp Show resolved Hide resolved
src/validation.cpp Show resolved Hide resolved
@azuchi azuchi merged commit 2b47dbf into chaintope:master Jul 5, 2023
@Naviabheeman Naviabheeman deleted the 254_stdThreads branch September 17, 2024 10:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants