C ++ 11应用程序使用dispatch_apply不能在Mac OS Sierra下工作 [英] C++11 app that uses dispatch_apply not working under Mac OS Sierra

查看:109
本文介绍了C ++ 11应用程序使用dispatch_apply不能在Mac OS Sierra下工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用C ++ 11编写的完全功能的代码库,它使用了Grand Central Dispatch并行处理,特别是 dispatch_apply 为一些琐碎的游戏计算做了基本的并行循环。

I had a completely functioning codebase written in C++11 that used Grand Central Dispatch parallel processing, specifically dispatch_apply to do the basic parallel for loop for some trivial game calculations.

自从升级到Sierra之后,该代码仍然运行,但每个块都是以串行方式运行的, cout 语句表明它们是以串行顺序执行的, CPU使用情况图表不显示并行处理。

Since upgrading to Sierra, this code still runs, but each block is run in serial -- the cout statement shows that they are being executed in serial order, and CPU usage graph shows no parallel working on.

队列定义为:

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 ++方法,我很抱歉。

I strongly suspect that this either a bug, but if this is GCD forcing me to use new C++ methods for this, I'm all ears.

推荐答案

我不知道这是否是一个错误塞拉或不。但是,如果您显式将全局并行队列作为目标关联,它似乎工作。

I'm not sure if it is a bug in Sierra or not. But it seems to work if you explicitly associate a global concurrent queue as target:

dispatch_queue_t target =
        dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0);
dispatch_queue_t workQueue = 
        dispatch_queue_create_with_target("workQueue", DISPATCH_QUEUE_CONCURRENT, target);
//                            ^~~~~~~~~~~                                         ^~~~~~

这篇关于C ++ 11应用程序使用dispatch_apply不能在Mac OS Sierra下工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆