Wednesday, 15 July 2015

iphone - NSOperationQueue blocking unrelated NSOperationQueue? -



iphone - NSOperationQueue blocking unrelated NSOperationQueue? -

i'm loading image in background using nsoperation , nsoperationqueue (for 2d game).

to understand how nsoperations behaves, i've tried adding next unrelated nsoperationqueue / nsoperation (i phone call -startnewendlessbackgroundtask way before starting image loading):

static int stop = no; static int c = 1000; -(void)taketime { stop = no; while (!stop) { (int = 0; < 10000; i++) { c += 1; } c = c; } } -(void)stopbackgroundtask { stop = yes; } -(void)startnewendlessbackgroundtask { //[self performselectorinbackground:@selector(taketime) withobject:nil]; nsoperationqueue* queue = [[nsoperationqueue alloc] init]; [queue addoperationwithblock:^{ [self taketime]; }]; }

this blocks other nsoperationqueue image loading on iphone4. on iphone4s, blocks image loading after 2 calls startnewendlessbackgroundtask. both running ios 6.

the main loop of app not blocked.

if instead utilize performselectorinbackground invoke taketime, works fine no blocking, , taketime routine working in background well.

why happening, when 2 nsoperationqueue's alloc-init'ted separately , have no dependencies? me, there shouldn't difference between using nsoperationqueue in simple way, , using performselectorinbackground, guess there fundamental misunderstanding?

not sure details, partial reply think happening..

nsoperation uses gcd underneath (at to the lowest degree since lastly few versions of osx , ios). there global priority queues in gcd.

when there task in higher priority queue, tasks in lower priority queues not started (though tasks in same global priority queue can start, since despite having "queue" in name, tasks in default priority queue can concurrent).

since don't specify thread priority, imagine -taketime operation beingness scheduled on default priority queue, , image loading operation beingness scheduled on default low priority queue. explain why -taketime operation blocking image loading.

what doesn't explain, why take 2 -taketime operations block image loading operation on iphone 4s, since tasks in low priority queues waiting tasks in high priority queues isn't mentioned contingent on number of cpu cores - far i've seen in docs.

apple - dispatch queues: "in add-on getting default concurrent queue, can queues high- , low-priority levels passing in dispatch_queue_priority_high , dispatch_queue_priority_low constants function instead, or background queue passing dispatch_queue_priority_background constant. might expect, tasks in high-priority concurrent queue execute before in default , low-priority queues. similarly, tasks in default queue execute before in low-priority queue."

iphone ios asynchronous concurrency nsoperation

No comments:

Post a Comment