-
Notifications
You must be signed in to change notification settings - Fork 4k
ARROW-13244: [C++] Add facility to get current thread id as uint64 #10644
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
Conversation
cpp/src/arrow/util/io_util.cc
Outdated
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.
So I did a bit of research on this out of curiosity. TL;DR: this should be safe enough.
std::thread::id is often a number, sometimes it is a pointer to a struct, and sometimes it is a struct (https://github.com/nginx/unit/blob/master/src/nxt_thread_id.h attempts to catalogue all the possible methods). I couldn't find any example where it is larger than 8 bytes. This approach has some precedent. OpenSSL originally required thread_id be coerced into unsigned long and now it has an implementation where it is either unsigned long or a pointer. However, I think that had to be done because on some systems a pointer may be larger than unsigned long. So I think uint64_t is safe since a pointer should never be larger than 8 bytes.
One potential concern is that technically == could be overloaded so that two threads could in theory have the same uint64_t representation but not be equal. One case is when a thread id is a pointer and that pointer is reused. However, the spec for std::thread states Once a thread has finished, the value of std::thread::id may be reused by another thread so this is already a given.
cpp/src/arrow/util/async_generator.h
Outdated
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.
I couldn't see any reason this wouldn't work but why not just use the uint64_t version of std::thread::id()? Is it to allow this to be constexpr?
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.
Hmm, I hadn't thought of that. But it seems simpler to use a hardcoded number like this.
5958ee3 to
4dce506
Compare
|
Rebased, will merge if green. |
Followup to #10632