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 12:02 PM, Antonio Nunes wrote:

The code below works fine in debug builds

[...]

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

[...]

Could this be a compiler bug

No. In the release build the compiler is applying optimizations given the information at its disposal. It sees that the same value is tested over and over again, so arranges to load the value only once when optimizations are on. (Look at the disassembly to verify this in your Release build.)


Using the volatlle type qualifier gives the compiler and optimizer more information to work with. (But see below.)

or is this not a good way to handle states across threads?

Even if you made changes to get this working, it is still very inefficient. You have a busy loop doing nothing but chewing cycles waiting for some other task to finish. There is likely a better solution, but you aren't going to get a quick or easy answer because we don't know the architecture of your program. Writing a multi- threaded application correctly is hard. At the very least, you'll want to start by reading the documentation Matt pointed you at.


Jim

_______________________________________________
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.