Question

I've got the following code in a thread in my application:

while (true) {
    if (ready) {
        progressIndicatorController.value++;
        return;
    }
}

The ready variable is changed from a delegate method. This code works great when I open the application by clicking the "Run" button in Xcode's toolbar. However, if I open this application's .app (which I create by clicking Product > Archive and then following the steps) this code somehow doesn't work anymore.

progressIndicatorController.value is never incremented and this if-statement never evaluates to true. What could cause this problem?

Was it helpful?

Solution

This is probably caused by optimization from the compiler.

When you build with Archive, XCode enabled optimization in the compiler that could throw this kind of code away. I think setting the ready variable to volatile could fix your problem, altough if I were you I'd just try to rewrite it so it doesn't trigger this problem.

You can test with optimization turned on by choosing Edit Schemes in the scheme dropdown. Then set Build Configuration to Release in the Run MyApp.app. Don't forget to set it back to Debug when you're done though, as the debugger gets somewhat confused when optimization are on (i.e. you can't see the value of most variables, some breakpoints may behave erratically, etc...)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top