• 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: Chris Hanson <email@hidden>
  • Date: Sat, 30 Sep 2006 21:35:47 -0700

On Sep 30, 2006, at 11:35 AM, Antonio Nunes wrote:

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.

Regardless, you need to protect your use that shared variable with a lock or other synchronization primitive. Doing so will ensure the compiler doesn't optimize it out or keep its value solely in a register (which means it won't be shared between the two threads), and is also simply correct multithreaded programming practice.


Ultimately, if you're going to build a multithreaded application, you should read up on the producer-consumer pattern and how to use it to implement work queues. Following established and well-understood patterns in writing multithreaded code will make it a lot easier to ensure your code both performs well and avoids deadlocks or other serious and difficult-to-correct threading bugs. It's also a lot easier than winging it...

  -- Chris

_______________________________________________
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: John Stiles <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>)
 >Re: Endless loop but only with release build (From: Antonio Nunes <email@hidden>)

  • Prev by Date: Re: Weird drawing trouble, please help me
  • 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