• 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
Endless loop but only with release build
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Endless loop but only with release build


  • Subject: Endless loop but only with release build
  • From: Antonio Nunes <email@hidden>
  • Date: Sat, 30 Sep 2006 17:02:18 +0100

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: This email sent to email@hidden
  • Follow-Ups:
    • Re: Endless loop but only with release build
      • From: Jim Correia <email@hidden>
    • Re: Endless loop but only with release build
      • From: Bill Bumgarner <email@hidden>
  • Prev by Date: NSTextField drawing over itself?
  • Next by Date: Re: NSTextField drawing over itself?
  • Previous by thread: Re: NSTextField drawing over itself?
  • Next by thread: Re: Endless loop but only with release build
  • Index(es):
    • Date
    • Thread