Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Endless loop but only with release build



Hi,

The code below works fine in debug builds, and a.f.a.i.k. up to now used to work fine also in release builds, but now, in release builds, it gets into an endless loop when trying to close the window while conversion is ongoing. I don't know whence the sudden change in behaviour, but I did find a work around: calling NSLog in the "while (_isConverting)" loop causes the loop to correctly exit in release builds too. Not just any call or assignment in the loop will result in an exit. So far I've found only calling NSLog does.

Causes endless loop in release build if _isConverting is YES when the while statement is reached.
- (BOOL)windowWillClose:(id)sender
{
#pragma unused (sender)
// Notify other threads that we will close
_isClosing = YES;

// Stop observing our sourcePages.
NSEnumerator *e = [sourcePages objectEnumerator];
ANSourcePage *sourcePage;
while (sourcePage = [e nextObject]) {
[self stopObservingSourcePage:sourcePage];
}

// Wait until the converting thread has terminated, if it exists
while (_isConverting) {
;
}

return YES;
}



With the following change the loop exists when supposed to: while (_isConverting) { NSLog(@""); ; }


Could this be a compiler bug, or is this not a good way to handle states across threads? (If I don't wait for _isConverting to become NO in windowWillClose then the app may crash when closing a window, hence the need for this loop.) Anybody an idea why this code above works fine in debug build and loops endlessly in release build?


XCode 2.4
MacOS X 10.4.7

Thanks,
António

-----------------------------------------
Forgiveness is not an occasional act;
it is a permanent attitude.

--Martin Luther King, Jr
-----------------------------------------




_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.