如何锁定/解锁交叉线程

时间:2015-06-10 13:36:08

标签: ios objective-c multithreading

对于某些代码段,我想逐个执行,例如:

self.coreDataLock = [[NSRecursiveLock alloc] init];

// Snippet One
[self.coreDataLock lock];
[childContext performBlock:^{
    // Do something
    [self.coreDataLock unlock];
}];

// Snippet Two
[self.coreDataLock lock];
dispatch_group_notify(group, dispatch_get_main_queue(), ^{
    // Do something
    [self.coreDataLock unlock];
});

但我无法锁定/解锁NSRecursiveLock交叉线程,如何弄明白?

0 个答案:

没有答案