-
Notifications
You must be signed in to change notification settings - Fork 237
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
[REQ] Getting thread ids #126
Comments
Thanks for opening this issue, @klytje! A similar feature is actually already implemented in v3.6.0, which should be released within a week or two. A new member function The downside is that the native handles are not guaranteed to be easily hashable for use in an associative container (although I don't really see why they shouldn't be). However, I am also introducing the option to have a thread initialization function that runs exactly once on each thread when the thread pool is constructed, which should allow you to get the thread IDs manually as you suggested. For this release I actually considered defining a built-in |
Yes I read both of those issues before opening this one, actually. I just thought that using handles or manually extracting the thread ids upon creation seemed like a round-about way of doing something quite simple. I suppose you're right that there's not a whole lot you can do with the thread ids except what I'm trying to accomplish here. |
In v3.6.0 there will be a function However, if you think there is some other use for it that |
I think it'd be useful to be able to get the thread ids of the threads currently in the pool. This would allow us to use thread-local data with a simple
std::unordered_map<std::thread::id, T>
.For me this would be useful for evaluating and binning Euclidian distances. Currently I am allocating a new result vector for every job, and then summing all of them at the end. If I had the thread ids, I could instead allocate only a single result vector for each thread, and then sum these at the end. This would dramatically reduce the time spent allocating and summing vectors.
Technically this should already be possible to do by submitting jobs getting the
std::this_thread::get_id()
once for each thread, but I am not sure how to guarantee that all threads run this job at least once without excessive looping or waiting.This can be implemented by adding the following to both header files:
The text was updated successfully, but these errors were encountered: