C ++ 11 application that uses dispatch_apply not working under Mac OS Sierra

I had a fully functioning code base written in C ++ 11 that used the parallel processing of Grand Central Dispatch, namely dispatch_apply, to make the base parallel for the loop for some trivial game calculations.

From the moment of upgrading to Sierra, this code is still executed, but each block is launched in sequential mode - the cout operator shows that they are executed in sequential order, and the CPU usage schedule does not work in parallel.

A queue is defined as:

workQueue = dispatch_queue_create("workQueue", DISPATCH_QUEUE_CONCURRENT); 

And the corresponding program code:

  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; } 

I strongly suspect that this is either a mistake, but if this GCD forces me to use the new C ++ methods for this, I’m all ears.

+1
source share
1 answer

I'm not sure if this is a mistake in the Sierra or not. But this seems to work if you explicitly bind the global parallel queue as the 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); // ^~~~~~~~~~~ ^~~~~~ 
+2
source

Source: https://habr.com/ru/post/1257669/


All Articles