-
Notifications
You must be signed in to change notification settings - Fork 35.6k
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
[WIP DONOTMERGE] Replace boost with C++17 (std::shared_mutex) #19183
Conversation
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsReviewers, 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. |
3bd1f19
to
cb4616b
Compare
@MarcoFalke Just an idea - it looks like
https://en.cppreference.com/w/cpp/filesystem Maybe it's already on your roadmap. I don't know. But I can give a hand if you like. (edit: see #19245) |
@@ -26,7 +26,7 @@ class CSignatureCache | |||
CSHA256 m_salted_hasher; | |||
typedef CuckooCache::cache<uint256, SignatureCacheHasher> map_type; | |||
map_type setValid; | |||
boost::shared_mutex cs_sigcache; | |||
std::shared_mutex cs_sigcache; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: I think this has little risk of difference with boost vs std since we never use a condition variable with this mutex.
offtopic note for anyone curious is that cs_sigcache is overkill since we generally know that there are no concurrent readers and writers ever, the read lock could be held at a higher layer for the entire span of block validation, it's just harder to expose the right API for that (@hebasto seems to be looking at this stuff so figured I would mention it somewhere).
a52ecc9 build: set minimum supported macOS to 10.14 (fanquake) Pull request description: This is a requirement for C++17 support. See my comments [here](bitcoin/bitcoin#16684 (comment)): > You cannot use std::get with std::variant on macOS < 10.14, because Apples libc++ doesn't support the std::bad_variant_access exception. [Relevant comment](bitcoin/bitcoin#19183 (comment)) in #19183. > While we could work around this in our own code, using std::get_if, this would still be a problem for 3rd-party dependencies. > I've been testing Qt 5.15LTS (we'll have to enable C++17 in qt, and may upgrade to a newer version at the same time), and you can't enable -std c++17, while targeting a macOS deployment version < 10.14, configuring will fail. They are making use of std::get with std::variant throughout their cocoa code. We would have to had to have bumped to at least 10.13 in any case, as Qt 5.15 (#19716) [requires 10.13+](https://doc.qt.io/qt-5/supported-platforms.html). ACKs for top commit: hebasto: ACK a52ecc9, I have reviewed the code and it looks OK, I agree it can be merged. Tree-SHA512: f669b2fc777aeea1e9afdbbc7bd9afe3997418211db6ba53c934cae0e62a9b999603da539518c229f34961d275c9e2f315c7b022cf5fb97bd201a69c85d470cc
Concept ACK @MarcoFalke What is left to do here until the "[WIP DONTMERGE]" can be dropped? :) |
commit a52ecc9 was required, which was only merged today |
Could 2d48314 also be reverted? |
src/optional.h
Outdated
template <typename T> | ||
using Optional = boost::optional<T>; | ||
using Optional = std::optional<T>; | ||
|
||
//! Substitute for C++17 std::make_optional | ||
template <typename T> | ||
Optional<T> MakeOptional(bool condition, T&& value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MakeOptional
can be dropped if these three workarounds are removed?
src/wallet/rpcwallet.cpp: Optional<int> height = MakeOptional(false, int()); // Height of the specified block or the common ancestor, if the block provided was in a deactivated chain.
src/wallet/rpcwallet.cpp: Optional<int> stop_height = MakeOptional(false, int());
src/wallet/wallet.cpp: Optional<int64_t> time_first_key = MakeOptional(false, int64_t());;
Concept ACK
and also like this idea |
bd7b071
to
b925981
Compare
@MarcoFalke CI is happily green now. Do you want to make any further changes before removing the draft status, or do you plan to submit these changes as individual PRs? I'm particularly looking forward to the |
A green CI doesn't mean there are no bugs. No one knows if the shared_mutex can be replaced at all: #19183 (comment) #16684 (comment) Also, commit 8b173d4 introduces a bug in the gui, which isn't covered by tests. Finally, optional can't be replaced with mechanical changes because the standard library doesn't have a non-throwing accessor by pointer. So the imo confusing use of the non-throwing accessor should be removed first. See #19426 |
void print_if(const std::optional<int>& val) {
if(val) {
std::cout << *val << "\n";
} else {
std::cout << "empty\n";
}
} |
What I meant to say was that it doesn't have a |
b925981
to
8af0f32
Compare
8af0f32
to
89a4f8d
Compare
Closing for now due to #19183 (comment) and #16684 (comment) |
060a2a6 ci: remove boost thread installation (fanquake) 06e1d7d build: don't build or use Boost Thread (fanquake) 7097add refactor: replace Boost shared_mutex with std shared_mutex in sigcache (fanquake) 8e55981 refactor: replace Boost shared_mutex with std shared_mutex in cuckoocache tests (fanquake) Pull request description: This replaces `boost::shared_mutex` and `boost::unique_lock` with [`std::shared_mutex`](https://en.cppreference.com/w/cpp/thread/shared_mutex) & [`std::unique_lock`](https://en.cppreference.com/w/cpp/thread/unique_lock). Even though [some concerns were raised](#16684 (comment)) in #16684 with regard to `std::shared_mutex` being unsafe to use across some glibc versions, I still think this change is an improvement. As I mentioned in #21022, I also think trying to restrict standard library feature usage based on bugs in glibc is not only hard to do, but it's not currently clear exactly how we do that in practice (does it also extend to patching out use in our dependencies, should we be implementing more runtime checks for features we are using, when do we consider an affected glibc "old enough" not to worry about? etc). If you take a look through the [glibc bug tracker](https://sourceware.org/bugzilla/describecomponents.cgi?product=glibc) you'll no doubt find plenty of (active) bug reports for standard library code we already using. Obviously not to say we shouldn't try and avoid buggy code where possible. Two other points: [Cory mentioned in #21022](#21022 (comment)): > It also seems reasonable to me to worry that boost hits the same underlying glibc bug, and we've just not happened to trigger the right conditions yet. Moving away from Boost to the standard library also removes the potential for differences related to Boosts configuration. Boost has multiple versions of `shared_mutex`, and what you end up using, and what it's backed by depends on: * The version of Boost. * The platform you're building for. * Which version of `BOOST_THREAD_VERSION` is defined: (2,3,4 or 5) default=2. (see [here](https://www.boost.org/doc/libs/1_70_0/doc/html/thread/build.html#thread.build.configuration) for some of the differences). * Is `BOOST_THREAD_V2_SHARED_MUTEX` defined? (not by default). If so, you might get the ["less performant, but more robust"](boostorg/thread#230 (comment)) version of `shared_mutex`. A lot of these factors are eliminated by our use of depends, but users will have varying configurations. It's also not inconceivable to think that a distro, or some package manager might start defining something like `BOOST_THREAD_VERSION=3`. Boost tried to change the default from 2 to 3 at one point. With this change, we no longer use Boost Thread, so this PR also removes it from depends, the build system, CI etc. Previous similar PRs were #19183 & #20922. The authors are included in the commits here. Also related to #21022 - pthread sanity checking. ACKs for top commit: laanwj: Code review ACK 060a2a6 vasild: ACK 060a2a6 Tree-SHA512: 572d14d8c9de20bc434511f20d3f431836393ff915b2fe9de5a47a02dca76805ad5c3fc4cceecb4cd43f3ba939a0508178c4e60e62abdbaaa6b3e8db20b75b03
No description provided.