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

ThreadPool::enqueue() failed to forward an argument as reference #67

Open
wanlizhu opened this issue Mar 6, 2019 · 3 comments
Open

Comments

@wanlizhu
Copy link

wanlizhu commented Mar 6, 2019

for example, the following test case will fail:

TEST(ThreadPool, Case1) {
ThreadPool pool(4);
int x = 1;

    auto res = pool.enqueue([](int& y){ y = 99; },  x);
    res.get();

    EXPECT_EQ(x, 99);

}

@fogti
Copy link

fogti commented Mar 6, 2019

I think std::ref is needed here. https://en.cppreference.com/w/cpp/utility/functional/ref

@wanlizhu
Copy link
Author

wanlizhu commented Apr 7, 2019

Thanks for your answer, it is correct now

@fogti
Copy link

fogti commented Apr 8, 2019

could you please close this issue, as it seems solved now?

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

No branches or pull requests

2 participants