Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7692603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:53:26+00:00 2026-05-31T20:53:26+00:00

So the first question is how does dispatch_async determines which thread to use? just

  • 0

So the first question is how does dispatch_async determines which thread to use? just picks it randomly? I need to do some parsing and core data stuff, so I don’t want to block UI thread and use dispatch_async, but after that I send a NSURLRequest to fetch some more data and the callback is never invoked (probably because the thread is already dead).

So what’s a good way of making it? And I can not use

sendAsynchronousRequest:queue:completionHandler: 

because the deployment OS is 4. for now I just send request inside

dispatch_async(dispatch_get_main_queue(), ^{
});

which is inside dispatch_async(myQueue) block which does all the parsing and saving to core data. But it does not seem right to me, I mean there should be a way to use dispatch_async and tell it not kill the tread, right? Because using sync requests is not an option.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T20:53:28+00:00Added an answer on May 31, 2026 at 8:53 pm

    So the first question is how does dispatch_async determines which thread to use?

    You should not be thinking of threads when using GCD. That’s all handled behind the scenes for you. You think in queues which is what you pass to dispatch_async along with the block to execute. A GCD queue does sort of map to a thread, but you don’t need to worry about what is going on behind the scenes – GCD will handle all that for you.

    As for your code which I assume looks similar to this:

    dispatch_async(myQueue, ^{
        // Do some stuff off the main queue
    
        dispatch_async(dispatch_get_main_queue(), ^{ 
            // Do something with the UI
        });
    });
    

    There is nothing wrong with that at all. You do not need to worry that the thread that the block you sent to myQueue runs on, might be terminated. The queue will stay around until the block as finished running. The fact that you dispatch onto the main queue within the original dispatch is fine – the work on the main queue will happily run perfectly fine.

    I think you’re also asking why when using NSURLRequest within an async dispatch you are seeing it not ever invoke the callback. That will be because it’s tightly coupled to the current run loop and if you’re currently on a background thread (which your myQueue will be running on) then that run loop won’t be run again until another block is put on the queue. So your callback never runs.

    I encourage you to go and read more about GCD and what async vs sync actually means as I feel that you are possibly not fully understanding it yet. I answered a similar question about that here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First, let me state that this is a programming question (and thus does not
This is actually a two part question. First,does the HttpContext.Current correspond to the current
First question so be gentle. I have been trying some projects involving the webbrowser
This is my first question on stackoverflow! I'm currently programming a steamcommunity crawler, which
this is my first question on stack overflow but I have some experience in
My first question is Does SQL Server work asynchronously or synchronously? if it works
My first question is basically asking for a code-review. Does the code I'm about
First the question: Why does the removal of const in UnregisterNode() cause failure, but
I have two questions (does that violate etiquette?) surrounding Twitter authentication. The first question
First look at this url: https://stackoverflow.com/questions/tagged/xoxoxo/ This directory does not exists but somehow stackoverflow

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.