Following is just a simple program to test using two threads to insert a hash table. For test no lock is used.
#include
#include
The error is very cryptic indeed, but the problem is that thread_add
takes its first parameter by reference, but you're passing it by value. This causes the functor type to be deduced wrong. If you want to pass something actually by reference to a functor like std::bind
or the main function of a std::thread
, you need to use a reference wrapper (std::ref
):
void test()
{
// ...
t[0] = thread(thread_add, std::ref(ht), 0, 9);
t[1] = thread(thread_add, std::ref(ht), 10, 19);
// ...
}
[Live example]