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

Re: Endless loop but only with release build


  • Subject: Re: Endless loop but only with release build
  • From: Antonio Nunes <email@hidden>
  • Date: Sat, 30 Sep 2006 19:35:29 +0100

On 30 Sep 2006, at 18:30, Bill Bumgarner wrote:
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.

Thanks Bill,

In practice, the loop should end almost immediately, because the task in the other thread will check a variable that will cause it to exit, so the busy-wait cycle is normally extremely short-lived. This was just my rather simplistic way of making sure the secondary thread exits before the window closes. But you're probably right that compiler optimization is causing the release build to fail.

I'll implement things more properly the way you suggest. Many thanks for the pointers, and thanks to Matt Neuburg for the link to the documentation on Cocoa Locks.

António

-----------------------------------------
Forgiveness is the perfume
that the trampled flower casts
upon the heel that crushes it.
-----------------------------------------



_______________________________________________
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: Chris Hanson <email@hidden>
References: 
 >Endless loop but only with release build (From: Antonio Nunes <email@hidden>)
 >Re: Endless loop but only with release build (From: Bill Bumgarner <email@hidden>)

  • Prev by Date: Re: Endless loop but only with release build
  • Next by Date: Re: Endless loop but only with release build
  • Previous by thread: Re: Endless loop but only with release build
  • Next by thread: Re: Endless loop but only with release build
  • Index(es):
    • Date
    • Thread