标签:sig notify sem creat async null 依赖 ado forever
创建一个值为M的信号量
如果该信号量的值大于0,则使其信号量的值-1,否则,阻塞线程直到该信号量的值大于0或者达到等待时间。
释放信号量,使得该信号量的值加1
dispatch_group_t group = dispatch_group_create();
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
dispatch_queue_t queue = dispatch_queue_create(NULL, DISPATCH_QUEUE_SERIAL);
for (int j = 0; j < 4; j ++) {
dispatch_group_async(group, queue, ^{
if (j == 0) {
[self loadOne:semaphore];
}else if (j == 1){
[self loadTwe:semaphore];
}else if (j == 2){
[self loadThree:semaphore];
}else{
[self loadFour:semaphore];
}
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
});
}
dispatch_group_notify(group, queue, ^{
//所有请求返回数据后执行
NSLog(@"完成");
});
标签:sig notify sem creat async null 依赖 ado forever
原文地址:https://www.cnblogs.com/xiyangxixia/p/11221473.html