Mailing Lists: Apple Mailing Lists

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

Re: Endless loop but only with release build



On Sep 30, 2006, at 9:02 AM, Antonio Nunes wrote:
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?

The compiler is likely optimizing a loop with no statements in its body. Possibly, a bug, even?


However, yes, this is not a good way to handle state across threads. It busy-waits the CPU, eating tons and tons of CPU spinning madly waiting for something to be done -- and slowing down the task that is running in the other thread (and everything else on the system). If this is a Cocoa app and you are busy waiting from the main thread, you have also rendered the application completely unresponsive.

For non-Cocoa apps, use a lock.

For Cocoa, use one of the methods that performs a selector (a method) on the main thread to pass notification between the threads.

b.bum

_______________________________________________
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
References: 
 >Endless loop but only with release build (From: Antonio Nunes <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.