I'm using the open source software TMCache. It saves expensive data to cache asynchronously. There is also a synchronous method.
It uses dispatch_semaphore_wait()
to wait until the operation is over.
- (id)objectForKey:(NSString *)key
{
if (!key)
return nil;
__block id objectForKey = nil;
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
[self objectForKey:key block:^(TMCache *cache, NSString *key, id object) {
objectForKey = object;
dispatch_semaphore_signal(semaphore);
}];
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
#if !OS_OBJECT_USE_OBJC
dispatch_release(semaphore);
#endif
return objectForKey;
}
This works fine on my machine. On a colleague's machine it does not.
The program stops working at dispatch_semaphore_wait()
. It's absolutely not reproducible for me.
The method above is called in tableView:viewForTableColumn:row:
,
so it's executed in the main queue.
Any idea why this is happening? Must I use the method in another queue?
objectForKey:block
. Are you sure that the block is being executed on your colleague's machine?key
isnil
?key
wasnil
,dispatch_semaphore_wait()
wouldn't be called in the first place...