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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T22:56:12+00:00 2026-06-09T22:56:12+00:00

-(void) test{ for(Person *person in persons){ __block CGPoint point; dispatch_async(dispatch_get_main_queue(), ^{ point = [self.myview

  • 0
-(void) test{
    for(Person *person in persons){
        __block CGPoint point;
        dispatch_async(dispatch_get_main_queue(), ^{
            point = [self.myview personToPoint:person];
        });
        usePoint(point); // take a long time to run
    }
}

I need to run personToPoint() in the main queue to get the point, and usePoint() method doesn’t need to run in main queue and take a long time to run. However, when running usePoint(point), point has not been assigned value because using dispatch_async. If using dispatch_sync method, the program will be blocked. the how can I using point after it has been assigned?

UPDATE:
how to implement the pattern of the following code:

-(void) test{
    NSMutableArray *points = [NSMutableArray array];
    for(Person *person in persons){
        __block CGPoint point;
        dispatch_async(dispatch_get_main_queue(), ^{
            point = [self.myview personToPoint:person];
            [points addObject:point];
        });
    }
    usePoint(points); // take a long time to run
}
  • 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-09T22:56:13+00:00Added an answer on June 9, 2026 at 10:56 pm

    Something like the following would work. You might also put the entire for loop inside one dispatch_async() and let the main thread dispatch all the usePoint() functions at once.

    -(void) test{
        for(Person *person in persons){
            dispatch_async(dispatch_get_main_queue(), ^{
                CGPoint point = [self.myview personToPoint:person];
                dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
                    usePoint(point); // take a long time to run
                });
            });
        }
    }
    

    Solution for Updated question:

    You use the same basic pattern as suggested above. That is you dispatch the stuff you need to do on the main thread to the main thread and then nest a dispatch back to a default work queue inside the main thread dispatch. Thus when the main thread finishes its work it will dispatch off the time consuming parts to be done elsewhere.

    -(void) test{
        dispatch_async(dispatch_get_main_queue(), ^{
            NSMutableArray *points = [NSMutableArray array];
            for (Person *person in persons){
                CGPoint point = [self.myview personToPoint:person];
                [points addObject:[NSValue valueWithCGPoint:point]];
            }
            dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
                usePoint(points); // take a long time to run
            });    
        });
    }
    

    Note that there was an error in your code as you can’t add CGPoint‘s to an NSArray since they are not objects. You have to wrap them in an NSValue and then unwrap them in usePoint(). I used an extension to NSValue that only works on iOS. On Mac OS X you’d need to replace this with [NSValue valueWithPoint:NSPointToCGPoint(point)].

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

Sidebar

Related Questions

i am trying to test this method: [Test] public void Test_GetReferenceValue() { Person person=
void test() { unsigned char c; c = (~0)>>1 ; printf(c is %u\n,c); }
public void test(Object obj){ //Here i have to set the values of the obj
Below is one of my C functiosn: void test(char * ptr) { ptr[0] =
static void testlock() { for(int i=0;i<10000000;i++) { float f=2.0/i; } } static void TEST()
I have interface Foo public interface Foo { public void test(); } Class FooChild
I am loading a certificate from string like this: public static void Test() {
I have the following simple code abstract class A { public abstract void Test(Int32
How do you do the equivalent of: [Test, ExpectedException( typeof(ArgumentOutOfRangeException) )] void Test_Something_That_Throws_Exception() {
I have one doubt regarding casting. public void Test(out T a, out T b)

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.