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

feat: simple thread pool #4137

Merged
merged 10 commits into from
Sep 2, 2022
Merged

Conversation

olgavrou
Copy link
Collaborator

@olgavrou olgavrou commented Sep 1, 2022

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

vowpalwabbit/core/include/vw/core/thread_pool.h Outdated Show resolved Hide resolved
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)
Copy link
Collaborator

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?

Copy link
Collaborator Author

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

Copy link
Member

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

Copy link
Collaborator Author

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)

vowpalwabbit/core/include/vw/core/thread_pool.h Outdated Show resolved Hide resolved
@olgavrou olgavrou enabled auto-merge (squash) September 2, 2022 17:36
@olgavrou olgavrou merged commit e908939 into VowpalWabbit:master Sep 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants