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

[BUG] Arguments are passed by value #83

Closed
ThibaultDECO opened this issue Sep 30, 2022 · 2 comments
Closed

[BUG] Arguments are passed by value #83

ThibaultDECO opened this issue Sep 30, 2022 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@ThibaultDECO
Copy link

It would be useful to specify in the documentation that, when submitting tasks, arguments are passed by value by default (see std::bind()), which can significantly slow down the pool.

And that one should use std::ref() to pass arguments by reference, such as:
auto my_future = pool.submit(task, arg1, std::ref(arg2));

It would be convenient if there was a way for arguments to be passed by reference automatically when the function definition specifies it, but not sure how to do it.

@ThibaultDECO ThibaultDECO added the bug Something isn't working label Sep 30, 2022
@bshoshany
Copy link
Owner

Thanks for the suggestion! I will incorporate this in the documentation in the next release.

Unfortunately, as far as I know, it's impossible to define submit() or push_task() so that they can accept references automatically. This is because std::function needs the std::ref (or std::cref for constant references) wrappers to be used explicitly in the constructor in order to take arguments that are references. (But if you find a way to bypass that, please let me know!)

@bshoshany
Copy link
Owner

Update: v3.5.0, which was just released, includes instructions for passing arguments by reference in README.md.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants