for (int s=0; s<masterArray.count; s++) {
for (int i=0; i<countOfSub1; i++) {
}
}
这个循环中的大量数据所以,我想在s = 0时得到然后得到第二个循环的所有数据然后在s = 1之后然后在得到第二个循环的所有数据之后,那么如何在此设置线程码。感谢。
答案 0 :(得分:1)
您可以通过以下示例使用它
for (int s=0; s<masterArray.count; s++) {// your main loop starts here
dispatch_semaphore_t sem;
sem = dispatch_semaphore_create(0);
dispatch_queue_t concurrentQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(concurrentQueue, ^{
for (int i=0; i<countOfSub1; i++) {// Inner loop in a thread
//your work here
}
dispatch_semaphore_signal(sem);
});
dispatch_semaphore_wait(sem, DISPATCH_TIME_FOREVER); // main loop waiting to be triggered from sub loop. (inner loop)
}