- (IBAction)serialSync:(id)sender {
NSLog(@"start log in main thread"]);
dispatch_queue_t myQueue = dispatch_queue_create("myQueue", NULL);
for (NSInteger n = 0; n < 3; n++) {
dispatch_sync(myQueue, ^{
for (NSInteger i = 0; i < 500000000; i++) {
if (i == 0) {
NSLog(@"串行同步任务%ld -> 开始%@",n,[NSThread currentThread]);
}
if (i == 499999999) {
NSLog(@"串行同步任务%ld -> 完成",(long)n);
}
}
});
}
NSLog(@"阻塞我没有?当前线程%@",[NSThread currentThread]);
}
- (IBAction)serialAsync:(id)sender {
NSLog(@"start log in main thread"]);
dispatch_queue_t myQueue = dispatch_queue_create("myQueue", NULL);//创建一个串行队列
for (NSInteger n = 0; n < 3; n++) {
dispatch_async(myQueue, ^{
for (NSInteger i = 0; i < 500000000; i++) {
if (i == 0) {
NSLog(@"串行异步任务%ld -> 开始%@",n,[NSThread currentThread]);
}
if (i == 499999999) {
NSLog(@"串行异步任务%ld -> 完成",(long)n);
}
}
});
}
NSLog(@"阻塞我没有?当前线程%@",[NSThread currentThread]);
}
- (IBAction)concurrentSync:(id)sender {
NSLog(@"start log in main thread"]);
dispatch_queue_t myQueue = dispatch_queue_create("myQueue", DISPATCH_QUEUE_CONCURRENT);
for (NSInteger n = 0; n < 3; n++) {
dispatch_sync(myQueue, ^{
for (NSInteger i = 0; i < 500000000; i++) {
if (i == 0) {
NSLog(@"并行同步任务%ld -> 开始%@",(long)n,[NSThread currentThread]);
}
if (i == 499999999) {
NSLog(@"并行同步任务%ld -> 完成",(long)n);
}
}
});
}
NSLog(@"阻塞我没有?当前线程%@",[NSThread currentThread]);
}
- (IBAction)concurrentAsync:(id)sender {
NSLog(@"start log in main thread"]);
dispatch_queue_t myQueue = dispatch_queue_create("myQueue", DISPATCH_QUEUE_CONCURRENT);
for (NSInteger n = 0; n < 3; n++) {
dispatch_async(myQueue, ^{
for (NSInteger i = 0; i < 500000000; i++) {
if (i == 0) {
NSLog(@"并行异步任务%ld -> 开始%@",n,[NSThread currentThread]);
}
if (i == 499999999) {
NSLog(@"并行异步任务%ld -> 完成",(long)n);
}
}
});
}
NSLog(@"阻塞我没有?当前线程%@",[NSThread currentThread]);
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有