Skip to content

build, util: name OpenBSD threads - #399

Merged
ryanofsky merged 1 commit into
bitcoin-core:masterfrom
ViniciusCestarii:name-openbsd-thread
Nov 24, 2026
Merged

ryanofsky merged 1 commit into
bitcoin-core:masterfrom
ViniciusCestarii:name-openbsd-thread

Conversation

@ViniciusCestarii

Copy link
Copy Markdown
Contributor

Add HAVE_PTHREAD_SET_NAME_NP and HAVE_PTHREAD_GET_NAME_NP macros to support OpenBSD thread names and also address #324 (comment)

@DrahtBot

DrahtBot commented Nov 17, 2026 •

Copy link
Copy Markdown

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

Reviews

See the guideline and AI policy for information on the review process.

Type Reviewers
ACK hebasto, xyzconstant, winterrdog

If your review is incorrectly listed, please copy-paste <!--meta-tag:bot-skip--> into the comment that the bot should ignore.

@nullfail nullfail left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ACK a67dd36

@hebasto hebasto left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Concept ACK.

A few notes not strictly related to this PR's changes:

  1. The current CI logs are not really helpful when tests could be skipped at compile time or at runtime. We could improve this. For example, we could either make the ctest output verbose or split the test binaries and let ctest manage them.

  2. The config macros set via #cmakedefine FOO ... are susceptible to misspelled macro names in the code going undetected (see bitcoin/bitcoin#36874).

#include <pthread_np.h>
int main()
{
char thread_name[16];

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why hardcoded 16?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Because ThreadName uses char[16] and this also matches HAVE_PTHREAD_GETNAME_NP

Comment thread src/mp/util.cpp
#elif defined(HAVE_PTHREAD_GETTHREADID_NP)
pthread_set_name_np(pthread_self(), name); // FreeBSD
#elif defined(HAVE_PTHREAD_SET_NAME_NP)
pthread_set_name_np(pthread_self(), name); // FreeBSD, OpenBSD, DragonFly

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Has someone tested this code on DragonFly?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Idk anyone who has tried this with Dragonfly. I added Dragonfly comment because it is one of the platform that Bitcoin Core checks to use pthread_set_name_np

Comment thread include/mp/config.h.in
Comment on lines +17 to +18
#cmakedefine HAVE_PTHREAD_SET_NAME_NP @HAVE_PTHREAD_SET_NAME_NP@
#cmakedefine HAVE_PTHREAD_GET_NAME_NP @HAVE_PTHREAD_GET_NAME_NP@

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I understand that these lines follow the already used pattern, but this would suffice:

Suggested change
#cmakedefine HAVE_PTHREAD_SET_NAME_NP @HAVE_PTHREAD_SET_NAME_NP@
#cmakedefine HAVE_PTHREAD_GET_NAME_NP @HAVE_PTHREAD_GET_NAME_NP@
#cmakedefine HAVE_PTHREAD_SET_NAME_NP 1
#cmakedefine HAVE_PTHREAD_GET_NAME_NP 1

@ViniciusCestarii ViniciusCestarii Nov 18, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Cool, do you think it would be better to replace all of those with 1?

Comment thread test/mp/test/test.cpp
}

#ifdef HAVE_PTHREAD_GETNAME_NP
#if defined(HAVE_PTHREAD_GETNAME_NP) || defined(HAVE_PTHREAD_GET_NAME_NP)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

While touching this line, it would be great to add an explanatory comment based on @ryanofsky's reasoning here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good idea. Done in a5e5585

@ViniciusCestarii

Copy link
Copy Markdown
Contributor Author

Thanks @xyzconstant and @hebasto for reviewing! Force-pushed a5e5585 addressing #399 (comment)

@hebasto hebasto left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ACK a5e5585.

@DrahtBot
DrahtBot requested a review from nullfail November 18, 2026 13:17

@nullfail nullfail left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

re-ACK a5e5585

Only change since last review was @hebasto's suggestion about putting a note over the #if defined(HAVE_PTHREAD_GETNAME_NP) || defined(HAVE_PTHREAD_GET_NAME_NP) line.

@winterrdog winterrdog left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

crACK a5e5585

Comment thread src/mp/util.cpp

} // namespace

// Copied from https://github.com/bitcoin/bitcoin/blob/d3e40af2597/src/util/threadnames.cpp#L21-L36

@winterrdog winterrdog Nov 19, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

just an observation while reviewing this.

are there intentions to align this code for both codebases since they have grown out of sync ?

in bitcoin/bitcoin there is no NetBSD or illumos support (i had plans to work on NetBSD but got occupied elsewhere), whereas it is covered here. conversely, bitcoin/bitcoin supports Windows but it is absent here


might be a good idea for a follow-up

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think it is good to keep them in sync when they share the same platform.

libmultiprocess doens't support Windows yet and illumos is not oficially supported by Bitcoin Core. NetBSD is the only outlier that Bitcoin Core oficially suports but don't name threads.

@ryanofsky
ryanofsky merged commit 213485d into bitcoin-core:master Nov 24, 2026
14 checks passed
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.

6 participants