• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: main thread communicating with background thread and vice-versa
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: main thread communicating with background thread and vice-versa


  • Subject: Re: main thread communicating with background thread and vice-versa
  • From: Joseph Kelly <email@hidden>
  • Date: Fri, 21 Nov 2008 07:01:37 -0800

How is your mainThreadParm declared? If it's a file global scope non- pointer value, it could be getting optimized away.

Try declaring it static or volatile.

Also, if threads are changing mainThreadParm independently in non- atomic ways, you will want to put locks around the critical sections.

Joe K.



On Nov 21, 2008, at 6:24, John Love <email@hidden> wrote:

From the main Thread, I call:



[NSThread detachNewThreadSelector:@selector(bgThread:) toTarget:self withObject:nil];



- (void) bgThread:(NSConnection*)connection {

   NSAutoreleasePool *pool;

   pool = [[NSAutoreleasePool alloc] init];



   [self doCalculation];



[self performSelectorOnMainThread:@selector(endBgCalculation:) withObject:nil waitUntilDone:NO];



   [pool release];

}



- (void) endBgCalculation:(id)obj {

       // stuff

}



I believe this is fairly standard way to institute a background thread …



The problem centers on letting the background Thread look at a parm set in the main Thread and break out of the background Thread when the background Thread sees a certain value.



Specifically, my –doCalculation is just one great time-consuming for -loop that looks at mainThreadParm and breaks depending on the valu e of mainThreadParm.



I change mainThreadParm in the main Thread and I expect the background Thread to break when the background Thread sees a certain value of mainThreadParm.



The background thread sees the initial value of mainThreadParm, but does not break when the main Thread changes it.



This sounds so basic and fundamental that I really feel lacking on this subject.



John Love

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >main thread communicating with background thread and vice-versa (From: John Love <email@hidden>)

  • Prev by Date: Re: Cocoa "canvas" view ?
  • Next by Date: Re: Tabbing to Placeholders
  • Previous by thread: main thread communicating with background thread and vice-versa
  • Next by thread: Re: main thread communicating with background thread and vice-versa
  • Index(es):
    • Date
    • Thread