Is there an advantage in the iPhone to split an operation into multiple streams?

I have a method in an application for iPhone that is very repeating (repeating sequentially and sequentially). The method is rather cumbersome and takes about one second.

My question is this: If I were to use muti-thread to run, say, 5 method calls on different threads at the same time, would it be faster than making 5 calls one after another? I know for desktops with multi-core processors this would be an advantage, but I'm not sure about the iPhone.

Any tips?

+3
source share
3 answers

Grand Central Dispatch ( GCD libdispatch), The Right Thing (tm).

dispatch_async , GCD , .

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
     // Do your calculations here

     // If you want to run code on the main loop with the result of the calculations,
     // do something like this
     dispatch_async(dispatch_get_main_queue(), ^{
         // Code to run on the main thread here
     });
});

.

Concurrency GCD .

Ars GCD. , GCD , .

+2

, . :

- (void) startInParallel {
    for (int i=0; i<5; i++)
        [self performSelectorInBackground:@selector(doSomeWork)];
}

, . , , , NSOperations GCD . ( , performSelectorInBackground .)

+2

- , , , , ( ). , . , , . NSOperation, .

+2

Source: https://habr.com/ru/post/1769980/


All Articles