The original source is as below :
for (auto &core : cores)
core->Run();
Member "cores" has the structure like below :
std::vector<std::unique_ptr<Core>> cores;
I tried to make the code above multi-threaded by changing the "for" loop :
for(auto &core : cores){
threads[i] = std::thread(core->Run, this);
i++;
}
i = 0;
for (auto &core : cores){
threads[i].join();
i++;
}
I get the following error :
error: no matching function for call to ‘std::thread::thread(<unresolved overloaded function type>, x86::Cpu* const)’
threads[i] = std::thread(core->Run, this);
(P.S. core->Run() is implemented in x86::Cpu::Run(), core->Run() is a method in a class x86::Core::Run())
I know what I did was kind of stupid, but I'm fairly new to using threads, so I'm having a hard time finding the right way to use these functions or understanding them at all.
I'm trying to make each core->Run() function run in a separate thread, but I'm getting confused of how to use the std::thread when the function is inside a vector of a unique_ptr, and I'm finding it hard to reference the method in the right way
I think my situation is kind of unique, I could not find anyone asking a question similar to mine