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

Proposal - Add API for getting/setting thread name in Boost? #84

Closed
bobsummerwill opened this issue May 9, 2016 · 5 comments
Closed

Comments

@bobsummerwill
Copy link

As discussed on the mailing list:

http://lists.boost.org/Archives/boost/2016/05/229385.php
http://lists.boost.org/Archives/boost/2016/05/229426.php
http://lists.boost.org/Archives/boost/2016/05/229452.php
(more to come)

The proposal is for us to add functions to the Boost thread API for getting and setting thread names (to ease debugging). It appears that there is quite well-known "cut-and-paste" boilerplate code for this on at least Windows, Linux and OS X and probably more. Can have common API, but the (very simple) implementation will vary.

If nobody else steps up, I would be happy to add this to my own backlog.

I've also been working with an external developer which is getting Ethereum
C++ working on Alpine Linux, as a statically linked executable using musl,
rather than glibc.
One rather confusing element was related to setting and getting thread
names, which is the process of working through this issue, I find appears
not to have made its way into either Boost or the C++11 standard library,
though it must be a very common cross-platform use-case.
ethereum/libweb3core#73
https://github.com/ethereum/libweb3core/pull/73/files
I've just added this comment-block, while fixing the issue:
/// Set the current thread's log name.
///
/// It appears that there is not currently any cross-platform way of setting
/// thread names either in Boost or in the C++11 runtime libraries. What is
/// more, the API for 'pthread_setname_np' is not even consistent across
/// platforms which implement it.
///
/// A proposal to add such functionality on the Boost mailing list, which
/// I assume never happened, but which I should follow-up and ask about.
/// http://boost.2283326.n4.nabble.com/Adding-an-option-to-set-the-name-of-a-boost-thread-td4638283.html
///
/// man page for 'pthread_setname_np', including this crucial snippet of
/// information ... "These functions are nonstandard GNU extensions."
/// http://man7.org/linux/man-pages/man3/pthread_setname_np.3.html
///
/// Stack Overflow "Can I set the name of a thread in pthreads / linux?"
/// which includes useful information on the minor API differences between
/// Linux, BSD and OS X.
/// http://stackoverflow.com/questions/2369738/can-i-set-the-name-of-a-thread-in-pthreads-linux/7989973#7989973
///
/// musl mailng list posting "pthread set name on MIPs" which includes the
/// information that musl doesn't currently implement 'pthread_setname_np'
/// https://marc.info/?l=musl&m=146171729013062&w=1
void setThreadName(std::string const& _n);
Would I be right in assuming that this never happened?
http://boost.2283326.n4.nabble.com/Adding-an-option-to-set-the-name-of-a-boost-thread-td4638283.html
If not, where can I log an issue to request that we revisit that? From
what I can see, everybody is likely just cut-and-pasting much the same code
for this functionality.
http://stackoverflow.com/questions/10121560/stdthread-naming-your-thread
Cheers,
Bob Summerwill

@bobsummerwill
Copy link
Author

PS. This all came out of the work at ethereum/webthree-umbrella#495.

@bobsummerwill
Copy link
Author

@viboes said ...

What I have in mind was to use the boost::thread_attributes, but we are unable to do it in OSX as the set name in OSX sets the name of the current thread :(
After some thought I believe we could do it by using a trampoline that will do the setting before calling the user main thread function, but this is more complex and needs to store the name in the thread_data context.

IIUC, what you are proposing and the single thing that could be done in an almost portable way and easily is to define two non-member functions to set and get the thread name on namespace this_thread or any other. Is this what you are proposing? If this is the case, this functionality can be developed completely independently of Boost.Thread, isn't' it?

@bobsummerwill
Copy link
Author

bobsummerwill commented May 10, 2016

Is this what you are proposing? If this is the case, this
functionality can be developed completely independently of Boost.Thread, isn't' it?

Maybe :-) I don't necessarily have a specific preference. I don't have deep knowledge of Boost's architecture. You would know better than me what the idiomatic way of achieving of this aim within Boost's existing patterns would be.

@viboes
Copy link
Collaborator

viboes commented Oct 9, 2018

Closed as no PR provided since more than 1 year

@viboes viboes closed this as completed Oct 9, 2018
@bobsummerwill
Copy link
Author

Hey @viboes!

So I "got busy" for 3 years, but I was wondering if this thread-naming functionality is still missing in Boost? If so, I might have another try at this.

Seems it is still missing in std::thread for sure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants