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 protected])

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to