//异步执行 + 并行队列
- (void)asyncConcurrent{
//创建一个并行队列
dispatch_queue_t queue = dispatch_queue_create("标识符", DISPATCH_QUEUE_CONCURRENT);
NSLog(@"---start---");
//使用异步函数封装三个任务
dispatch_async(queue, ^{
NSLog(@"任务1---%@", [NSThread currentThread]);
});
dispatch_async(queue, ^{
NSLog(@"任务2---%@", [NSThread currentThread]);
});
dispatch_async(queue, ^{
NSLog(@"任务3---%@", [NSThread currentThread]);
});
NSLog(@"---end---");
}
//异步执行 + 串行队列
- (void)asyncSerial{
//创建一个串行队列
dispatch_queue_t queue = dispatch_queue_create("标识符", DISPATCH_QUEUE_SERIAL);
NSLog(@"---start---");
//使用异步函数封装三个任务
dispatch_async(queue, ^{
NSLog(@"任务1---%@", [NSThread currentThread]);
});
dispatch_async(queue, ^{
NSLog(@"任务2---%@", [NSThread currentThread]);
});
dispatch_async(queue, ^{
NSLog(@"任务3---%@", [NSThread currentThread]);
});
NSLog(@"---end---");
}
//同步执行 + 并行队列
- (void)syncConcurrent{
//创建一个并行队列
dispatch_queue_t queue = dispatch_queue_create("标识符", DISPATCH_QUEUE_CONCURRENT);
NSLog(@"---start---");
//使用同步函数封装三个任务
dispatch_sync(queue, ^{
NSLog(@"任务1---%@", [NSThread currentThread]);
});
dispatch_sync(queue, ^{
NSLog(@"任务2---%@", [NSThread currentThread]);
});
dispatch_sync(queue, ^{
NSLog(@"任务3---%@", [NSThread currentThread]);
});
NSLog(@"---end---");
}
- (void)syncSerial{
//创建一个串行队列
dispatch_queue_t queue = dispatch_queue_create("标识符", DISPATCH_QUEUE_SERIAL);
NSLog(@"---start---");
//使用异步函数封装三个任务
dispatch_sync(queue, ^{
NSLog(@"任务1---%@", [NSThread currentThread]);
});
dispatch_sync(queue, ^{
NSLog(@"任务2---%@", [NSThread currentThread]);
});
dispatch_sync(queue, ^{
NSLog(@"任务3---%@", [NSThread currentThread]);
});
NSLog(@"---end---");
}
- (void)asyncMain{
//获取主队列
dispatch_queue_t queue = dispatch_get_main_queue();
NSLog(@"---start---");
//使用异步函数封装三个任务
dispatch_async(queue, ^{
NSLog(@"任务1---%@", [NSThread currentThread]);
});
dispatch_async(queue, ^{
NSLog(@"任务2---%@", [NSThread currentThread]);
});
dispatch_async(queue, ^{
NSLog(@"任务3---%@", [NSThread currentThread]);
});
NSLog(@"---end---");
}
- (void)syncMain{
//获取主队列
dispatch_queue_t queue = dispatch_get_main_queue();
NSLog(@"---start---");
//使用同步函数封装三个任务
dispatch_sync(queue, ^{
NSLog(@"任务1---%@", [NSThread currentThread]);
});
dispatch_sync(queue, ^{
NSLog(@"任务2---%@", [NSThread currentThread]);
});
dispatch_sync(queue, ^{
NSLog(@"任务3---%@", [NSThread currentThread]);
});
NSLog(@"---end---");
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有