Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
3.50/5 (2 votes)
See more:
I've written a program in VS C++ 2008. During debugging the Runtime Library is Multi-threaded Debug. Then I decided it was good enough and compiled a release version. Output to the window failed to work and the program generally did not behave well.

After much time placing Message Boxes in the program I determined that the initial problem is in writing to the display. Nothing I looked at looked wrong so I took a look at the Properties under the Release Configuration. It appears that there are four settings for the Runtime Library, two for static linking and two for dynamic. Initially I chose static linking so that made the choice of the debug and release versions of the static library. Just for grins I compiled the release program with the debug version of the static library. The program runs with the debug version of the library and does not run with the release version of the library.

So what is the problem? It is pretty clear that I cannot "fix" the problem in my code if I don't have any idea what the issue is.

Bob Van Tuyl
rrvt@swde.com

P.S. I know the library choice suggests that the program has a thread issue. I don't know if that is the case because I am creating a single window application using the MFC library. All the library choices in Visual Studio 2008 seem to be Multi-threaded. The code that I wrote does not employ threads directly (although Windows behind the scenes could).

After reading the article described below about moving from debug to release I now believe that I have a more elusive bug that has been masked by the debug version of the library. At least that is where I will spend the next session exploring. Thanks to all that have answered this vague question.
Posted
Updated 22-Nov-13 11:22am
v2
Comments
Ron Beyer 22-Nov-13 16:15pm    
So all you've told us is that its misbehaving and you have a library that works in debug mode but not release mode... How are we supposed to help? Its pretty clear that we cannot help you with the code unless you explain what problem you are seeing and maybe even show us some code!
Sergey Alexandrovich Kryukov 22-Nov-13 17:00pm    
Nevertheless, 3 people already answered, including myself. I have serious reasons to suspect just one source of problem to be more likely than others, please see Solution 3. Of course, just speculations.
—SA
Bob Van Tuyl 22-Nov-13 17:15pm    
Sorry, I know that I did not give enough information to point to a specific solution but the article described below gave me a number of things to look for.

The program is pretty large and complex and even the area where I suspect the first bug exists is too complex to describe in a simple description. I also suspect that I am going to try a lot of things described in the articles suggested below before I hit on the specific problem. I hope it is something simple like an uninitialized variable but I don't imagine that I will be that lucky.

Thanks for all the reponses.

Have a look at the oldie-goldie Newcomer's article: "Surviving the Release Version"[^].
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 22-Nov-13 16:59pm    
Fair enough, a 5, but... With threading, there is at least one much reason to run into problem, more likely than others. Please see Solution 3.
—SA
Bob Van Tuyl 22-Nov-13 17:07pm    
Thank you. The article and those it points to give me many avenues to explore.
CPallini 22-Nov-13 18:29pm    
You are welcome.
I thing the posts which appeared before this one helped you to understand that there is no enough information. So, don't expect mode then some abstracted speculations, pure shooting off the hips.

Threading is such a thing which cannot be fixed by just debugging reasonably well, the correctness should be proven theoretically. You can have a program which works well for months or even year, and, by pure accident, fall into a disaster. This is because intrinsic randomness is involved. And still, it's quite possible to write correct multithreaded applications, and, in many cases, it's not even too difficult.

So, my idea is: this might be not that your application ran correctly and failed by some mistake, it could be worse: the fact that is seemed to work on your development computer was the real mistake, in fact it was not failing by mistake, and, in production, it "legitimately" failed. It happens. Why the difference? Timing. In different environment, timing has shifted just a bit.

Such things happen when the design of your code contained race conditions: http://en.wikipedia.org/wiki/Race_condition[^].
When I first read about this, it has a more informative name: "incorrect dependency of the time of execution". The real practical danger of this thing is not that something fails. The problem is that race condition allows things to work in indeterminate way and create an illusion of correct work. Consider tho threads, one is multiplying some shared variable by a constant, another one adds a constant. And all the shared object are perfectly synchronized. However, if, say, the shared variable equals 2, the the result could be either 2*3 + 4 or (2+4) * 3. It's 10 or 18, depending on what thread comes first. Consider you expect 10, and the first thread always gets access to this variable a bit sooner, by some random timing reason. Now, imagine that timing is slightly shifted, so the first thread gets a tiny delay, say, because some user started MS Word at that time. And then you get 18, even though you got only 10, during many days of testing.

And please don't rush to say "I cannot have it, because I never multiplied a value by 3 in one thread and add 4 in another one. I don't know; you could do something else. :-)

Again, there is no enough information; and this is just speculations. However, the race condition would be the primary suspect to me. Check it up first.

—SA
 
Share this answer
 
Comments
Bob Van Tuyl 22-Nov-13 17:24pm    
Thanks, as I clarified above, I don't have any explicit threads (although there may be some implicit threads due to windows) in the program, so no race conditions are fixable by me.
Sergey Alexandrovich Kryukov 22-Nov-13 18:24pm    
I cannot see your code, so I cannot confirm that or argue against that, I just see your words "Multi-threaded Debug/Release Issue". Threads are threads, explicit or implicit, and something in your code is certainly fixable, I don't know who will fix what.
—SA
CPallini 22-Nov-13 18:31pm    
5.
Sergey Alexandrovich Kryukov 22-Nov-13 19:18pm    
Thank you, Carlo.
—SA
Depends on exactly how it is misbehaving but in normal C++ (unmanaged in general) what you described is caused by a pointer problem. The difference is explained because the different libraries have different code paths which alter how the program runs.

The same can be said about a thread issue as well though. It might work better because you haven't correctly protected data that is accessed by different threads. The different libraries impact the timing and/or the way the data is managed and so it seems to work better.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 22-Nov-13 16:58pm    
"Different code paths" is pretty unlikely. With threading, there is at least one much more likely reason. Please see Solution 3.
—SA
jschell 23-Nov-13 16:58pm    
Err...do you know what the difference between debug libraries and release libraries is?
Bob Van Tuyl 22-Nov-13 17:10pm    
Thank you. I will examine the issues suggested by the article given above (and your suggestion is included in the article).
Thanks to all that responded to this vague question. The solution was suggested by the paper "Surviving the Release Version" suggested above. The actual solution was a class with an incomplete initialization during construction. I actually visited each class and initialized all simple variables (those not automatically initialized by its' own constructor). While doing this I would test the release version and one of the more complex modules (classes) needed some additional initialization.

Now that I've fixed this problem I must express my disapointment with Microsoft for creating the situation in the first place. Back when I started in this business (in one of the first time sharing machines developed at UC Berkeley) our debuggers worked in the same environment as the final product. Thus not debugging meant removing the symbol table and running the program (and no other changes). This meant that bugs could be found and then reliably fixed in the environment in which the program would run. Oh well, time moves on and thoughts about how to accomplish a goal change, perhaps not always for the better...

Bob Van Tuyl

Thanks to all...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900