• 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: Mon, 24 Nov 2008 08:22:30 -0800

From what I can tell, clicking the button is not setting mainThreadParm = kStopped. Set a breakpoint in your action method to verify. Since (I assume) mainThreadParm is a member variable of your Controller class instance (and therefore accessible to all object methods of the class) it won't be optimized away (i.e. you don't need to declare the varaible w/ the volatile keyword).

Joe K.

On Nov 24, 2008, at 3:55 AM, John Love wrote:

Joseph ...

For now, my time consuming for-loop is empty for testing purposes. For now, I artificiallyincrease the time consumed by increasing the upper bound of the loop.

The mainThreadParm is an integer and is a parm in the existing Controller's interface, that is the main thread.

Actually, mainThreadParm is typed as an ErrorCode, where
    typedef int   ErrorCode;

mainThreadParm starts out in the main Thread = 13.

The for-loop of the background thread (doCalculation:) looks like:

int row;

for (row=1; row <= 100000; row++) {  // large upper bound

    if (mainThreadParm == kStopped) break;  // kStopped = 15

}

By clicking a button in the main Thread, I change mainThreadParm = kStopped (= 15) and it does not communicate with the background Thread this change.

After the for-loop, the background Thread is done, so [self performSelectorOnMainThread:@selector(endBgCalculation:) withObject:nil waitUntilDone:NO] is called.

Within my -endBgCalculation, I do a NSLog(@"mainThreadParm = %d", mainThreadParm). This call to NSLog shows a value of mainThreadParm = 13 which is what mainThreadParm started out as before the for- loop. My change to kStopped = 15 from the main Thread is never seen by the background Thread.

?????

John

_______________________________________________

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>)
 >Re: main thread communicating with background thread and vice-versa (From: Joseph Kelly <email@hidden>)

  • Prev by Date: Re: Killing a Thread
  • Next by Date: Re: Killing a Thread
  • Previous by thread: Re: main thread communicating with background thread and vice-versa
  • Next by thread: Tabbing to Placeholders
  • Index(es):
    • Date
    • Thread