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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:03:28+00:00 2026-05-27T20:03:28+00:00

I get some doubts about behavior of this code : dispatch_async(queue, ^{ sleep(2); NSLog(@step1);

  • 0

I get some doubts about behavior of this code :

dispatch_async(queue, ^{
    sleep(2);
    NSLog(@"step1");

    dispatch_sync(queue, ^{
        sleep(3);
        NSLog(@"step 2");
    });

    NSLog(@"step 3");
});

From these rows i expected to get as output step1 -> step3 -> step2 but i obtain only step1.

If i change dispatch_sync with dispatch_async it works as expected, Does dispatch_sync into a dispatch_async call create this kind of problem ?

Edit after answers —————-

This case create a deadlock:

You can check accepted answer to have explanation of this situation and check this link for documentation http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man3/dispatch_async.3.html

  • 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-27T20:03:28+00:00Added an answer on May 27, 2026 at 8:03 pm

    That’s a deadlock.

    The dispatch_sync call will be waiting until queue is available before running its block and returning but that won’t be available until the dispatch_async has finished so it will just sit there spinning waiting to call dispatch_sync.

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

Sidebar

Related Questions

For some reason I get some warnings about non dll-interface class when building with
I'm trying to get some code working that a previous developer has written. Yep,
Could I get some confirmations from the community that I'm not going mad, and
Can I get some constructive feedback about the following architecture? Simplified Architecture Summary: Return
After another question about iterators I'm having some doubts about custom containers. In my
I have some doubts: I want to show the photos from my company facebook
I am developing a JCA adapter and I have some doubts about my implementation
I'm thinking about using as a base some FIFO (for example, BoundedFifoBuffer from Apache
To get some smooth graphics, I want to draw oversampled by factor 2 and
Where can I get some decent looking free ASP.Net or CSS themes?

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.