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

  • Home
  • SEARCH
  • 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 7809089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:19:10+00:00 2026-06-02T03:19:10+00:00

My problem is that I’m using dispatch_async(dispatch_get_main_queue(), ^(void) { … }); to call a

  • 0

My problem is that I’m using dispatch_async(dispatch_get_main_queue(), ^(void) { ... }); to call a method asynchronously, in this method depending on some conditions i set a boolean to YES. When this boolean is read in this method, it’s always read by it’s old value which is NO.

The weird thing is that when i made a breakpoint on the line where the bool is checked, everything went fine and as intended !

EDIT:
Here is the code where the threads are spawned

dispatch_async(dispatch_get_main_queue(), ^(void) {
    [self drawFaceBoxesForFeatures:features forVideoBox:claporientation:curDeviceOrientation image:img];
});

The method itself

- (void)drawFaceBoxesForFeatures:(NSArray *)features forVideoBox:(CGRect)clap orientation:    (UIDeviceOrientation)orientation image:(UIImage *)image;
{
    if (![self getSendingRequestStatus]) {
        NSLog(@"Sending req");
        // send async request

         dispatch_async(dispatch_get_main_queue(),^ {
             sendingRequest = YES;
         } );
      }
}
  • 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-02T03:19:11+00:00Added an answer on June 2, 2026 at 3:19 am

    It looks like you are modifying an ivar that was created outside of a block inside of the block. In order to do this and have the ivar hold the correct value, you are going to need to use the __block keyword like so:

    @interface MyCoolClass : NSObject {
        @private
        __block int sendingRequest_;
    }
    

    As Jack Lawrence said in the commend above, “[the runtime] takes a snapshot of all of the relevant objects/variables at that point in time”. The __block identifier will tell the runtime that it should not copy that ivar to the heap and will allow you to assign values to sendingRequest_ inside of a block, even if that block is simply being run on the main thread.

    A lot of good information to start with (including the above) can be found in the Blocks Programming Guide.

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

Sidebar

Related Questions

I'm solving some problem that involves Rabin–Karp string search algorithm. This algorithm requires rolling
Ok I have this problem that I've never had before, it's really bugging me.
I'm facing a problem that seems to have no straighforward solution. I'm using java.util.Map
(I have a problem that I illustrated in this question but had no correct
This is a problem that is quite the opposite of the regular use of
The problem that i am having is I am using a touch listener for
This is a design problem that I am trying to figure out. I will
I have a problem that i've struggled with for a long time. This problem
This is an interview problem that I am stuck on: Given a string consisting
I am having this problem that I had used Arraylist in my entire program

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.