-
Notifications
You must be signed in to change notification settings - Fork 267
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] Resource Binding #104
Comments
I think a better solution would be to pass a function that takes thread id as a parameter to constexpr auto thread_count = 12;
std::array<Resource, thread_count> resource_array;
thread_local Resource* thread_resource;
...
BS::thread_pool pool{thread_count, [&resource_array](int thread_id) {
thread_resource = &resource_array[thread_id];
}}; In this case locking is not needed, but you can make array local to caller function (which is likely a good idea) and move its members to thread local variable instead of storing a pointer. Or initialize resources directly in threads instead of caller, which makes sense for a lot of resource types. A major reason I'd like to see this approach implemented instead of resource binding is because it allows to set up OpenGL context for every thread in pool, something that specifically requires running initialization code once per thread. Merely binding resource to thread would not allow this (well, you can make a thread local flag and check it at the beginning of every task, but just doing initialization properly is a much better idea). Plus this should be easier to implement than resource binding approach. |
That's a good approach. I will try. Thank you! |
Got it |
@v1993 According to your approach, the variable |
@v1993 Or we can create a map from |
@poor1017 you should wait for v4.0.0, to be released soon, which will implement thread initialization functions and will show some examples of how to use them. It will also have a function to get the index of the current thread, so there's no need for a map. |
nice! |
Describe the new feature
Can we support binding a resource to a thread?
Code example
The text was updated successfully, but these errors were encountered: