progschj / ThreadPool

A simple C++11 Thread Pool implementation
zlib License
7.64k stars 2.21k forks source link

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

Open wanlizhu opened 5 years ago

wanlizhu commented 5 years ago

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 commented 5 years ago

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

wanlizhu commented 5 years ago

Thanks for your answer, it is correct now

fogti commented 5 years ago

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