0

If I do this:

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
[self someMethod];
 });

And someMethod is this:

-(void)someMethod{
  //doing stuff with no mention of GCD
 }

Will someMethod run inside the dispatch queue, or will that queue wait for someMethod to run on the main thread, since someMethod does not itself dispatch anything to other queues?

1
  • someMethod won't run on the main thread, and won't wait for anything on the main thread to finish either. It will run in a different thread which has a high priority. Commented Aug 20, 2012 at 4:03

1 Answer 1

4

Methods are executed on the thread or queue from which they are invoked. So, if you wanted to update UI after processing data on a background queue, you'd need to explicitly execute your UI update on the main thread.

For example:

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
   [self someMethod];
});

- (void) someMethod{
    dispatch_async(dispatch_get_main_queue(), ^{
        // Update UI here
    });
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.