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 6739209
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:27:36+00:00 2026-05-26T11:27:36+00:00

Example: dispatch_sync(someConcurrentQueue, ^(){ dispatch_apply(5,someConcurrentQueue, ^(size_t i){ // do some non-thread safe operation }); });

  • 0

Example:

dispatch_sync(someConcurrentQueue, ^(){
    dispatch_apply(5,someConcurrentQueue, ^(size_t i){
        // do some non-thread safe operation
     });
});

I decided to test this out and noticed that the non-thread safe operation performed as expected. However, when I called dispatch_sync using a global queue, things quickly deteriorated.

So my questions are:
1. What is happening under the hood with a call like that?
2. Is every iteration of dispatch_apply being preemptively scheduled on its own thread then executing serially?
3. If the answer to 2 is yes, would doing this inside of an infinite loop be a performance increase? The reasoning being that operation could start executing as soon as the last one finished instead of looping again.

  • 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-26T11:27:37+00:00Added an answer on May 26, 2026 at 11:27 am

    This is roughly the same as:

    dispatch_sync(someConcurrentQueue, ^(){
        for (size_t i = 0; i < 5; ++i){
            dispatch_async(someConcurrentQueue, ^(){
                // do some non-thread safe operation
            });
        }
    });
    

    The operations would be enqueued on the same queue, which thread the code will run on is more of an implementation detail. As such if you did this in an infinite loop it would look something like this:

    • sync
    • async(0)
    • async(1)
    • async(2)
    • async(3)
    • async(4)
    • sync
    • …

    As your next dispatch_sync will get executed once dispatch_apply has been scheduled (not executed) your queue will increase in size very quickly.

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

Sidebar

Related Questions

Consider this contrived example: # Dispatch on value of fruit_kind: TYPE_A = :apple TYPE_B
Example: The user login to the webpage => Click on a button This action
I am trying to get some code working from an example I came across.
In this example , employee structs are parsed in the form employee{int, string, string,
I'm starting learning some about CouchDB by the Definiteve Guide. There is example -
Here's some code that catches an exception thrown on the Event Dispatch Thread: package
http://site2.example.com/ Error=> Notice: Trying to get property of non-object in /var/www/site/application/layouts/scripts/layout.phtml on line 19
In the example for coding with Json using Databinder Dispatch Nathan uses an Object
Example: You have a shortcut s to SomeProgram in the current directory. In cmd.exe
Example I have Person , SpecialPerson , and User . Person and SpecialPerson are

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.