-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
feat: simple thread pool #4137
feat: simple thread pool #4137
Conversation
std::packaged_task<ResultType()> task(std::bind(std::forward<F>(func), std::forward<Args>(args)...)); | ||
std::future<ResultType> result(task.get_future()); | ||
|
||
if (_threads.size() == 0) |
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.
what's the use case for initializing a thread pool with zero threads?
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.
maybe you don't want to branch your code based on zero threads vs more than one thread
plus this ensures that you don't just hang if you initialize with zero by mistake
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.
In my opinion initializing with zero threads should be an error. If the user doesn't want threading they shouldnt use a thread pool. It's not up to the thread pool to implement that
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 like to think as scaling naturally with the available resources without having to have a different code path (similar to std async)
introduced to be used in LAS
will probably evolve to include some sort of thread pool interface
when there is no work to be done threads wait on a conditional variable
if thread pool is initialized with zero size then the tasks are just executed sequentially on the same thread that called the thread pool