PDA

View Full Version : Release version crashes, debug version runs as expected



kghose
2nd October 2008, 16:17
Hi,

I have a strange problem. I have an app that uses threads to do some lengthy computations (triggered by some user interaction). These threads can be manipulated by the user by further user interactions.

When I compile the app in debug mode the application runs as expected - I can start one of these threads and then press keys to alter their operation. When I compile in release mode, however, trying to manipulate the thread causes an application crash.

Has any one had this kind of issue before, does anyone have an idea of why debug and release would create different behaviors like this?

I'm using QT4.1 on Mac OS X

Thanks
-Kaushik

caduel
2nd October 2008, 16:49
You have somewhere "undefined behaviour".
Undefined can mean: crashes now and then, or crashes in release but not debug build, or vice versa. So it is pure (bad) luck that the crash does not happen in the debug build.

Likely causes:
* thread not synced properly (a accesses to common data protected by a mutex?)
* array bounds violation

Try running your program through valgrind. Maybe you get a hint from there.

HTH

jpn
2nd October 2008, 17:03
It could be an uninitialized variable which gets initialized to a sane value in debug mode.

elcuco
2nd October 2008, 20:33
This is called the Heisenberg Principle. It origins from physics (see the wikipedia entry: http://en.wikipedia.org/wiki/Uncertainty_principle). The idea is that when want to measure a system, you insert a probe to measure it, and thus you change the system. It applies to software as well (read the Popular culture (http://en.wikipedia.org/wiki/Uncertainty_principle#Popular_culture) part of the wikipedia entry for more "implementations" of this principle).

The application crashes due to a race condition, you put a
printf() which changes the internal timings (or compile in debug mode, which might be slower, faster, or just different), different commands get scheduled differently - oops, no problem :p

Now the fun part of my responce: good luck, you will need it.

netuno
2nd October 2008, 22:03
I have a similar problem. Works on debug, but no on release. To make it special, this happens on linux. On windows it's the other way around. I've yet to find any reason for this behavior. My solution ends up being this:

win32 {
CONFIG += release
}

linux-g++ {
CONFIG += debug
}

I also run strip on the app on linux to get a smaller size for it. It's not always 0s and 1s...

Good luck, but don't wast to much time on this quest. It might not be worth it.

kghose
5th October 2008, 05:12
Thanks for your replies guys.

I solved it by basically going back and rewriting the thread more cleanly, so that its behavior to stochastic (i.e. user) input is more robust.

I don't know what the exact problem was, but the code looks prettier now and, it works both in debug and release!

-Kaushik