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

Dangerous code regarding parameter lifetime #45

Closed
horde3d opened this issue Mar 15, 2018 · 1 comment
Closed

Dangerous code regarding parameter lifetime #45

horde3d opened this issue Mar 15, 2018 · 1 comment
Labels

Comments

@horde3d
Copy link

horde3d commented Mar 15, 2018

Passing the parameters by reference to the std::thread object probably will result in a crash for most users, if they don't take care that those parameters have to be valid and constant for the whole thread lifetime.

std::thread downloading([&]() { this->sync_download(remote_file, local_file, callback, std::move(progress)); });

Instead of capturing the parameters with a lambda expression it would be probably better to pass the parameters as a thread local copy, e.g. by passing the function parameters as parameters to the thread instance.

@rusdevops
Copy link
Collaborator

Thank you for your code review 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants