|
// |
|
// GCD_Test.m |
|
// GCD_TEST |
|
// |
|
// Created by fengyi on 2014/11/19. |
|
// Copyright (c) 2014年 fytsai. All rights reserved. |
|
// |
|
|
|
#import "GCD_Test.h" |
|
|
|
@implementation GCD_Test |
|
|
|
-(void) gcd_main_queue{ |
|
dispatch_queue_t main_queue = dispatch_get_main_queue(); |
|
NSLog(@"HELLO"); |
|
dispatch_async(main_queue, ^{ |
|
NSLog(@"async:%@",[NSThread currentThread]); |
|
dispatch_async(main_queue, ^{ |
|
NSLog(@"async-async:%@",[NSThread currentThread]); |
|
}); |
|
|
|
dispatch_sync(main_queue, ^{ |
|
NSLog(@"sync-async:%@",[NSThread currentThread]); |
|
}); |
|
}); |
|
|
|
dispatch_sync(main_queue, ^{ |
|
NSLog(@"sync:%@",[NSThread currentThread]); |
|
dispatch_sync(main_queue, ^{ |
|
NSLog(@"sync-sync:%@",[NSThread currentThread]); |
|
}); |
|
|
|
dispatch_async(main_queue, ^{ |
|
NSLog(@"sync-async:%@",[NSThread currentThread]); |
|
}); |
|
|
|
}); |
|
} |
|
|
|
-(void) gcd_concurrent_queue{ |
|
dispatch_queue_t concurrent_queue = dispatch_queue_create("fytsai", DISPATCH_QUEUE_CONCURRENT); |
|
NSLog(@"HELLO"); |
|
dispatch_async(concurrent_queue, ^{ |
|
NSLog(@"async:%@",[NSThread currentThread]); |
|
dispatch_async(concurrent_queue, ^{ |
|
NSLog(@"async-async:%@",[NSThread currentThread]); |
|
}); |
|
|
|
dispatch_sync(concurrent_queue, ^{ |
|
NSLog(@"sync-async:%@",[NSThread currentThread]); |
|
}); |
|
}); |
|
|
|
dispatch_sync(concurrent_queue, ^{ |
|
NSLog(@"sync:%@",[NSThread currentThread]); |
|
dispatch_sync(concurrent_queue, ^{ |
|
NSLog(@"sync-sync:%@",[NSThread currentThread]); |
|
}); |
|
|
|
dispatch_async(concurrent_queue, ^{ |
|
NSLog(@"sync-async:%@",[NSThread currentThread]); |
|
}); |
|
|
|
}); |
|
} |
|
|
|
-(void) gcd_serial_queue{ |
|
dispatch_queue_t serial_queue = dispatch_queue_create("fytsai", DISPATCH_QUEUE_SERIAL); |
|
NSLog(@"HELLO"); |
|
dispatch_async(serial_queue, ^{ |
|
NSLog(@"async:%@",[NSThread currentThread]); |
|
dispatch_async(serial_queue, ^{ |
|
NSLog(@"async-async:%@",[NSThread currentThread]); |
|
}); |
|
|
|
dispatch_sync(serial_queue, ^{ |
|
NSLog(@"sync-async:%@",[NSThread currentThread]); |
|
}); |
|
}); |
|
|
|
dispatch_sync(serial_queue, ^{ |
|
NSLog(@"sync:%@",[NSThread currentThread]); |
|
dispatch_sync(serial_queue, ^{ |
|
NSLog(@"sync-sync:%@",[NSThread currentThread]); |
|
}); |
|
|
|
dispatch_async(serial_queue, ^{ |
|
NSLog(@"sync-async:%@",[NSThread currentThread]); |
|
}); |
|
|
|
}); |
|
} |
|
|
|
-(void) gcd_global_queue{ |
|
dispatch_queue_t global_queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); |
|
NSLog(@"HELLO"); |
|
dispatch_async(global_queue, ^{ |
|
NSLog(@"async:%@",[NSThread currentThread]); |
|
dispatch_async(global_queue, ^{ |
|
NSLog(@"async-async:%@",[NSThread currentThread]); |
|
}); |
|
|
|
dispatch_sync(global_queue, ^{ |
|
NSLog(@"sync-async:%@",[NSThread currentThread]); |
|
}); |
|
}); |
|
|
|
dispatch_sync(global_queue, ^{ |
|
NSLog(@"sync:%@",[NSThread currentThread]); |
|
dispatch_sync(global_queue, ^{ |
|
NSLog(@"sync-sync:%@",[NSThread currentThread]); |
|
}); |
|
|
|
dispatch_async(global_queue, ^{ |
|
NSLog(@"sync-async:%@",[NSThread currentThread]); |
|
}); |
|
|
|
}); |
|
} |
|
@end |