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?
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 , .
, . :
- (void) startInParallel { for (int i=0; i<5; i++) [self performSelectorInBackground:@selector(doSomeWork)]; }
, . , , , NSOperations GCD . ( , performSelectorInBackground .)
- , , , , ( ). , . , , . NSOperation, .
NSOperation
Source: https://habr.com/ru/post/1769980/More articles:Incompatibility between ggplot2 and other packages in R? - r"Compiling php" as well as porting - phpЧто такое PyObjC? - pythonPorting C ++ to C # - c ++Where should I do the availability check? - iosThe application did not start on time, even with a background thread - debuggingHow to make photo management in PHP? - phpRails 3 - How to define ActiveModel translations for multiple attributes? - yamlOpening a new form in Silverlight for Windows Phone 7 - windows-phone-7Creating your own C ++ OpenGL 3D editor and using it as a WinForms or WPF control in C # - c ++All Articles