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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:30:40+00:00 2026-05-24T06:30:40+00:00

I am relatively new to objective-c, and having an issue of thread synchronization. I

  • 0

I am relatively new to objective-c, and having an issue of thread synchronization. I am trying to return an image to the user (through the user supplied image url). I am initiating the image download in a separate thread, with the thread function declared and defined in my current class. The problem is though the thread is getting executed, my image downloading functionality is not working (i.e none of the NSURLConnection methods are getting called.

My class function for initiating thread and image download is:

- (NSMutableData*)download:(NSString*)strURL
{
    self.strURLData=strURL;
    [NSThread detachNewThreadSelector:@selector(threadMethod:) toTarget:[ICacheImageDownloadMgr class] withObject:self];
    //Here ICacheImageDownloadMgr is my current class
    while(!bCompletionFlag)
    {
        if(bCompletionFlag)//bCompletionFlag is set to TRUE in NSURLConnection::connectionDidFinishLoading method after successful image download
        {
            return currentData;
        }
    }
}

My only motive here is to return “currentData” after the image download process has completed, to the user.
And the thread method declared in my current class (i.e., ICacheImageDownloadMgr) is:

+ (void) threadMethod:(ICacheImageDownloadMgr*)param
{
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init];

    if(param.currentData)
    {
        [param.currentData release];
        param.currentData=nil;
    }
    param.currentData   = [[NSMutableData alloc]initWithLength:0];  

    NSURL *myURL = [[NSURL alloc] initWithString:param.strURLData];
    NSURLRequest *URLRequest = [NSURLRequest requestWithURL: myURL];
    param.urlcon = [[NSURLConnection alloc]initWithRequest:URLRequest delegate:self startImmediately:YES];
    [myURL release];

    param.dataLock = [[NSLock alloc]init];

    while(!param.bCompletionFlag)
    {
        if([param.dataLock tryLock])
        {
            if(param.bCompletionFlag)//bCompletionFlag is set to TRUE in NSURLConnection::connectionDidFinishLoading method after successful image download, along with NSLock unlock call
            {
                break;
            }
        }
    }

    [pool release];

}

Please let me know as to what I am doing wrong here? It seems both my threads here are into blocking and that’s why my NSURLConnection methods are not getting called. Again, as stated earlier, my only aim is to return “currentData” to the user.

Thanks,

  • 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-24T06:30:41+00:00Added an answer on May 24, 2026 at 6:30 am

    In your code:

    param.urlcon = [[NSURLConnection alloc]initWithRequest:URLRequest delegate:self startImmediately:YES];

    will start an async connection which relies on delegate methods to let you manage the ongoing transfer. You are not providing the implementation of your delegate methods, so I cannot say what is happening there,

    On another note, since you are starting a thread for your requests, you could simplify your life and make them synchronous (and actually I think this is what you were aiming at in the first place), so you do not have to deal with the delegate protocol. You can use the

    + sendSynchronousRequest:returningResponse:error:
    

    method for that, e.g.:

    [NSURLConnection sendSynchronousRequest:URLRequest returningResponse:&yourResponse error:&yourError];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm relatively new to objective-C and I'm having a problem with a 2D NSMutableArray
I'm relatively new to Objective-C and really don't know much about it yet, so
Note: I'm relatively new to Objective-C and am coming from Java and PHP. Could
I'm relatively new to Objective-C + Quartz and am running into what is probably
Being relatively new to programming--think Programming in Objective-C by Kochan, Chapter 15--I'm wondering if
I'm relatively new to Objective C and while I've been trucking right along writing
Im an experienced actionscript developer, and relatively new to Objective C. I decided a
I'm relatively new to objective-c...I'm using the iphone 3.0 SDK I have a UIView,
I am relatively new to Objective C and need some array help. I have
Relatively new to dealing with XML in jQuery. I am trying to retrieve a

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.