ios - Queueing with dispatch -


i creating queue @ first compress images in background , add dictionary in main queue. next images comprised , added print message. not archive code. why?

dispatch_sync(dispatch_get_global_queue(dispatch_queue_priority_default, 0), ^{      nsmutablearray *images = [_adv[@"images"] mutablecopy];     (nsmutabledictionary *i in images)     {         uiimage *large = [uiimage compressimage:i[@"original"]];          dispatch_async(dispatch_get_main_queue(), ^{              i[@"large"] = large;             [i removeobjectforkey:@"original"];         });     }       dispatch_sync(dispatch_get_main_queue(), ^{          nslog(@"%@", _adv);         nslog(@"\n ГОТОВО");     }); }); 

try reserve main queue user interactive work.

you should create own queue interacting mutable data structures. suggest using concurrent queue purpose. writing should done barrier.

you should background processing on background queue, , should doing things async don't need results after kicking off job , don't want block calling thread on background work.

i suggest doing more (written directly here, there may minor bugs):

dispatch_async(dispatch_get_global_queue(dispatch_queue_priority_default, 0), ^{     nsarray *images = _adv[@"images"];     (nsmutabledictionary *i in images.copy)     {         uiimage *large = [uiimage compressimage:i[@"original"]];          dispatch_barrier_sync(queuethatyouhavetoguardaccesstothesedata, ^{             i[@"large"] = large;             [i removeobjectforkey:@"original"];         });     }      dispatch_async(dispatch_get_main_queue(), ^{         nslog(@"%@", _adv);         nslog(@"\n ГОТОВО");     }); }); 

note you'll need create queuethatyouhavetoguardaccesstothesedata concurrent queue ahead of time. better have queuethatyouhavetoguardaccesstothesedata input function or have single mutex per image (or collection or that) avoid having single global write lock.


Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -