在看线程锁时,无意间看到block的递归调用,之前一直没有想怎么进行block递归调用,这里记录一下。
static NSRecursiveLock *lock;
if (lock == nil) {
lock = [[NSRecursiveLock alloc] init];
}
static void (^__block DoLog)(int) = ^(int value){
[lock lock];
if (value > 0) {
DoLog(value-1);
}
NSLog(@"value is %d", value);
[lock unlock];
};
dispatch_async(dispatch_get_global_queue(0, 0), ^{
NSLog(@"test begin");
DoLog(5);
NSLog(@"test end");
});