原始来源如下:
for (auto &core : cores)
core->Run();
成员“核心”具有如下结构:
std::vector<std::unique_ptr<Core>> cores;
我尝试通过更改“for”循环使代码变为多线程:
for(auto &core : cores){
threads[i] = std::thread(core->Run, this);
i++;
}
i = 0;
for (auto &core : cores){
threads[i].join();
i++;
}
我收到以下错误:
error: no matching function for call to ‘std::thread::thread(<unresolved overloaded function type>, x86::Cpu* const)’
threads[i] = std::thread(core->Run, this);
(PS core-&gt; Run()在x86 :: Cpu :: Run()中实现,core-&gt; Run()是类x86 :: Core :: Run()中的方法
我知道我所做的有点愚蠢,但我对使用线程相当新,所以我很难找到使用这些功能或理解它们的正确方法。
我正在尝试让每个core-&gt; Run()函数在一个单独的线程中运行,但是当函数在unique_ptr的向量中时,我对如何使用std :: thread感到困惑,而且我发现很难以正确的方式引用该方法
我认为我的情况有点独特,我找不到有人提出类似我的问题