Call performSelectorInBackground: from background theme

What is the real effect of calling performSelectorInBackground:...from a method that runs in the background? I want it to run asynchronously

For instance:

- (void) _imageBufferWasUpdated{
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

    //do something here

    if(shouldContinue){ 
        [self performSelectorInBackground:@selector(_loop) withObject:nil];
    }
    [pool release];
}

_imageBufferWasUpdated will execute in the background, and I want to call the _loop method asynchronously (in the background also _imageBufferWasUpdated will end soon, probably before _loop finishes).

Is it correct?

Is there a more efficient (and relatively simple) way to do this with a GCD? I would appreciate it if you could give an example on how to do this using GCD. It seems to me that I need at least 3 threads, the main thread, the background thread to run _imageBufferWasUpdated, and another background thread for _loop. Am I right?

Thanks in advance Ignacio

+3
2

, , . Cocoa, , , .

, NSOperation GCD. . , GCD ,

#import <dispatch/dispatch.h>

...

dispatch_async( dispatch_get_global_queue(0,0), ^{
    [self _loop];
}];
+2

performSelectorInBackground . [documentation]

, , , GCD (NSOperationQueue). , .

GCD , .

+1

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


All Articles