ThreadPool icon indicating copy to clipboard operation
ThreadPool copied to clipboard

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

Open wanlizhu opened this issue 7 years ago • 3 comments

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);

}

wanlizhu avatar Mar 06 '19 09:03 wanlizhu

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

fogti avatar Mar 06 '19 13:03 fogti

Thanks for your answer, it is correct now

wanlizhu avatar Apr 07 '19 15:04 wanlizhu

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

fogti avatar Apr 08 '19 19:04 fogti