Skip to content

Conversation

@maflcko
Copy link
Member

@maflcko maflcko commented Apr 24, 2020

There are predefined interruption points for boost::thread: https://www.boost.org/doc/libs/1_71_0/doc/html/thread/thread_management.html#interruption_points

However, non-boost threads such as std::thread or the main() thread can obviously not be interrupted. So remove all unused boost/thread from methods that are never executed in a boost::thread.

Most of them were accompanied by a ShutdownRequested anyway. So even if the current thread was a boost::thread, the interruption point would be redundant. (We only interrupt threads during shutdown)

@hebasto
Copy link
Member

hebasto commented Apr 24, 2020

Concept ACK.

@practicalswift
Copy link
Contributor

Concept ACK

@DrahtBot
Copy link
Contributor

DrahtBot commented Apr 24, 2020

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, this pull request conflicts with the following ones:

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@hebasto
Copy link
Member

hebasto commented Apr 27, 2020

fad6f40af271bd6094a70fea8311e5d0d18e7ae7 how about

catch (const boost::thread_interrupted&) {
throw;
}
?

@maflcko maflcko marked this pull request as draft April 29, 2020 01:38
@laanwj
Copy link
Member

laanwj commented Apr 30, 2020

Concept ACK.

@maflcko maflcko force-pushed the 2004-noBoostThread branch 2 times, most recently from fae70ac to 1123846 Compare June 2, 2020 14:39
@fanquake
Copy link
Member

fanquake commented Jun 2, 2020

Concept ACK. Not thread related, but could throw in:

diff --git a/src/init.cpp b/src/init.cpp
index 37e625129..438dc3762 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -71,9 +71,7 @@
 #include <sys/stat.h>
 #endif
 
-#include <boost/algorithm/string/classification.hpp>
 #include <boost/algorithm/string/replace.hpp>
-#include <boost/algorithm/string/split.hpp>
 #include <boost/signals2/signal.hpp>
 #include <boost/thread.hpp>

to remove some more Boost includes.

@hebasto
Copy link
Member

hebasto commented Jun 2, 2020

@fanquake

Concept ACK. Not thread related, but could throw in:

diff --git a/src/init.cpp b/src/init.cpp
index 37e625129..438dc3762 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -71,9 +71,7 @@
 #include <sys/stat.h>
 #endif
 
-#include <boost/algorithm/string/classification.hpp>
 #include <boost/algorithm/string/replace.hpp>
-#include <boost/algorithm/string/split.hpp>
 #include <boost/signals2/signal.hpp>
 #include <boost/thread.hpp>

to remove some more Boost includes.

The same cleanup is done in 46838e9 from #18710. Mind reviewing it?

@maflcko maflcko force-pushed the 2004-noBoostThread branch from 1123846 to 830c07e Compare June 2, 2020 18:33
@maflcko maflcko force-pushed the 2004-noBoostThread branch from 830c07e to 89f9fef Compare June 4, 2020 14:06
@maflcko maflcko marked this pull request as ready for review June 4, 2020 14:08
@maflcko
Copy link
Member Author

maflcko commented Jun 4, 2020

Rebased and cherry-picked one commit by @hebasto

Copy link
Member

@hebasto hebasto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 89f9fef, tested on Linux Mint 19.3 (x86_64), verified shutdown in different scenarios.

Copy link
Member

@fanquake fanquake left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 89f9fef

fad8c89: Checked that the calls to CCoinsViewDB::Upgrade and CBlockTreeDB::LoadBlockIndexGuts only happen in the [init] thread. As mentioned both of these calls were followed by a ShutdownRequested() anyways.

faa958b: Checked that txindex is run in a std::thread.

bitcoin/src/index/base.cpp

Lines 311 to 313 in 01b45b2

m_thread_sync = std::thread(&TraceThread<std::function<void()>>, GetName(),
std::bind(&BaseIndex::ThreadSync, this));

Also followed by a call to ShutdownRequested().

@fanquake fanquake merged commit 4ede05d into bitcoin:master Jun 5, 2020
@maflcko maflcko deleted the 2004-noBoostThread branch June 5, 2020 12:38
@maflcko
Copy link
Member Author

maflcko commented Jun 5, 2020

🥳

Thanks everyone for the reviews on this set! Now all boost thread interruption points are removed:

sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Jun 5, 2020
89f9fef refactor: Specify boost/thread/thread.hpp explicitly (Hennadii Stepanov)
fad8c89 txdb: Remove unused boost/thread (MarcoFalke)
faa958b txindex: Remove unused boost/thread (MarcoFalke)

Pull request description:

  There are predefined interruption points for `boost::thread`: https://www.boost.org/doc/libs/1_71_0/doc/html/thread/thread_management.html#interruption_points

  However, non-boost threads such as `std::thread` or the `main()` thread can obviously not be interrupted. So remove all unused boost/thread from methods that are never executed in a `boost::thread`.

  Most of them were accompanied by a `ShutdownRequested` anyway. So even if the current thread was a `boost::thread`, the interruption point would be redundant. (We only interrupt threads during shutdown)

ACKs for top commit:
  fanquake:
    ACK 89f9fef
  hebasto:
    ACK 89f9fef, tested on Linux Mint 19.3 (x86_64), verified shutdown in different scenarios.

Tree-SHA512: 17221dadedf2d107e5bda9e4f371cc4f8ffce6ad27cae41aa2b8f1150d8f1adf23d396585ca4a2dd25b1dc6f0d5c81fecd950d8557966ccb45a6d4a85a331d90
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request May 14, 2021
Summary:
> txindex: Remove unused boost/thread

> txdb: Remove unused boost/thread

> refactor: Specify boost/thread/thread.hpp explicitly

> There are predefined interruption points for boost::thread: https://www.boost.org/doc/libs/1_71_0/doc/html/thread/thread_management.html#interruption_points
>
> However, non-boost threads such as std::thread or the main() thread can obviously not be interrupted. So remove all unused boost/thread from methods that are never executed in a boost::thread.
>
> Most of them were accompanied by a ShutdownRequested anyway. So even if the current thread was a boost::thread, the interruption point would be redundant. (We only interrupt threads during shutdown)

To make it work for our codebase, I had to add an addition include in system.cpp and core_io_tests.cpp.

This is a backport of [[bitcoin/bitcoin#18758 | core#18758]]

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, majcosta, deadalnix

Reviewed By: #bitcoin_abc, majcosta, deadalnix

Subscribers: majcosta

Differential Revision: https://reviews.bitcoinabc.org/D9522
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Feb 15, 2022
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.

6 participants