Note that there are some explanatory texts on larger screens.

plurals
  1. POIs ALAssetsLibrary thread safe (Deadlock occurs when using multiple threads)
    primarykey
    data
    text
    <p>I'm currenly working on a tiny project which amis to loading ALL gallery photos into my app to show some fancy effect. Unfortunately, these default thumbnail provided by system cannot meet my requirement. So I try to create my own thumbnails using "fullScreenImage". To speed up the process, I load fullScreenImage using background operations. The main methods are:</p> <pre><code>- (void)getFullScreenImage:(NSURL *)url success:(void(^)(UIImage *))callback { NSLog(@"Requesting %@", url); [assetsLibraryInstance assetForURL:url resultBlock:^(ALAsset *asset) { callback(asset.defaultRepresentation.fullScreenImage); } failureBlock:nil]; } - (void)processURLs:(NSArray *)urls { for (NSURL *url in urls) { dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0) ^{ [self getFullScreenImage:url success:^(UIImage *img) { NSLog(@"Got image %@", img); }] ; }); } } </code></pre> <p>Only the "Requesting..." log is printed in console, the "getFullScreenImage" method is locked, no any output.</p> <p>I tried below methods to work around this issue:</p> <ol> <li>Not sharing assetsLibraryInstance (Didn't work)</li> <li>Don't dispatch_async when enumeate urls in "processURLs". (Did work, but I don't want to use a signle thread to process all URLs)</li> <li>Not using global queue, using main queue (Did work, but all these "fullScreenImage" works were doing on UI thread, making UI non-responsive)</li> <li>Using a private queue created with "dispatch_queue_create". (Didn't work)</li> </ol> <p>So, is ALAssetsLibrary thread safe? I guess it's not... Or, is there any better way I can use to:</p> <ol> <li>Load fullScreenImage in background</li> <li>Multiple threading</li> </ol> <p>Thanks!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload