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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T22:04:49+00:00 2026-06-10T22:04:49+00:00

I have written a simple test case that follows Apple’s documentation and I am

  • 0

I have written a simple test case that follows Apple’s documentation and I am not seeing the results that I’m expecting.

Here’s the code:

- (void)testExample2
{
    NSLog(@"1");

    dispatch_semaphore_t semaphore = dispatch_semaphore_create(0); 

    dispatch_async(dispatch_get_main_queue(), ^{
        NSLog(@"3");
             dispatch_semaphore_signal(semaphore);
        });

    NSLog(@"2");
    dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);

    NSLog(@"4");    
    dispatch_release(semaphore);    
}

I would expect to read: 1, 2, 3, 4 but instead my console just shows me 1, 3.

I’ve been able to work around the issue using DISPATCH_TIME_NOW in a while loop together with a NSLoop hack but the code above should kind of work… right?

Cheers…

UPDATE

I just realised that I should be using a separate queue rather than dispatch_main_queue()

  • 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-06-10T22:04:51+00:00Added an answer on June 10, 2026 at 10:04 pm

    Ended up doing the following in my tearDown.

    while (dispatch_semaphore_wait(semaphore, DISPATCH_TIME_NOW)) {
        NSLog(@"...Tearing Down Tests..");
        [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode
                                 beforeDate:[NSDate dateWithTimeIntervalSinceNow:10]];
    }
    dispatch_release(semaphore);  
    

    and pushing the semaphore creation into the setUp.

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

Sidebar

Related Questions

I have written a very simple test application that creates a websocket and parses
This is a simple script I have written to test command line argument handling:
I have written a simple WCF service that accepts and stores messages. It works
I have written a simple WPF application in which I wanted to test the
Studing STL I have written a a simple program to test functors and modifiers.
I have written a simple test class for Play! 2.0: public class TestLogin {
I'm trying to implement the String.Containts function. I have written some simple tests case,
I have written a test case which shows the error from unittest import *
I have written the following simple test in trying to learn Castle Windsor's Fluent
I have written a simple activity to test out services and broacast receivers and

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.