NSOperation、dispatch_semaphore_t、子线程while
子线程while:
- (void)viewDidLoad {
[super viewDidLoad];
queue = dispatch_queue_create("com.xx.test", DISPATCH_QUEUE_SERIAL);
[self test];
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
dic = [NSDictionary dictionary];
}
- (void)test {
dispatch_async(queue, ^{
BOOL finish = NO;
while (!finish) {
if (self->dic) {
NSLog(@"done");
finish = YES;
}
}
});
}
网友评论