1
我有一个用C++ 11编写的完全正常运行的代码库,它使用了Grand Central Dispatch并行处理,具体来说就是dispatch_apply做一些循环的基本并行微不足道的游戏计算。C++ 11应用程序使用dispatch_apply不适用于Mac OS Sierra
由于升级到塞拉利昂,该代码仍然运行,但每块串行运行 - 在COUT声明显示,他们是在串行顺序执行,并且CPU占用率曲线图显示没有并行工作。
队列被定义为:
workQueue = dispatch_queue_create("workQueue", DISPATCH_QUEUE_CONCURRENT);
和有关程序代码是:
case Concurrency::Parallel: {
dispatch_apply(stateMap.size(), workQueue, ^(size_t stateIndex) {
string thisCode = stateCodes[stateIndex];
long thisCount = stateCounts[stateIndex];
GameResult sliceResult = playStateOfCode(thisCode, thisCount);
results[stateIndex] = sliceResult;
if ((stateIndex + 1) % updatePeriod == 0) {
cout << stateIndex << endl;
}
});
break;
}
我强烈怀疑这两种错误,但如果这是GCD强迫我使用新的C++这方面的方法,我都耳熟能详。
这似乎已经解决了这个问题。现在,我只需要找到一种方法来使用Swift 3 * DispatchQueue.concurrentPerform(iterations:)*方法来完成这项工作,该方法似乎仍然存在该错误。但我很欣赏解决方法! – Charles
我不认为你会对Swift 3足够了解,建议如何利用Swift并发方法的类似解决方法,如 http://stackoverflow.com/questions/39843007/swift-app-using- dispatchqueue-concurrentperformiterations-no-longer-runs-conc 尽管感谢您的时间,但绝对感谢您的帮助! – Charles