Application crash due to change in compiler settings
-
Hi, I am currently working on a legacy MultiThreaded MFC application which talks to the remote hardware over a network. The application is compiled with VC++ 6.0 SP5 and has many dlls (Regular, Extension, C++ and WIN32). Now here is a typical user scenarion 1. The user starts a wizard to generate a report for a particular parameter usage on the remote hardware. 2. Configures the report parameters through wizard walkthrough and creates a task that will send some commands to the remote hardware and fetch the required data. The task is executed immidiately. Now here is a problem I faced during the recent Release build for internal testing due to accidental change in compiler settings. The application was originally configured to compile with optimization set to "complie for speed" for the Release builds. When the binary created with this setting is executed, the application runs perfectly fine. The user starts the wizard configure parameters create and execute the task. The application fetches the required data and generates the report. Now if the compiler setting is changed to optimization=disable with rest every thing remaining same, the application crashes with bad memory reference during the task execution. During a task execution there may be 3 to 5 threads (worker + GUI) running depending on the complexity of the requested task. I did found out that the crash was due to invalid thread handle value for one of the threads by attaching the VC debugger externally (On running the release build of the application from within the VC debugger, it works perfectly fine, strange !!!???). Breakpoints are not helping as it seems that they introduces enough time delay for the thread handle to be valid. I am not too sure on whether the handle is getting invalid either due to not getting initialized at all (the thread is created externally and then set as a reference in class object) or getting terminated too soon. Well guys I really need help on this as I have been struggling with it for 2-3 days and it is driving me nuts !! 1. I will really like to know what caused the problem at the first place ? 2. What really happened when optimization is turned off that lead to application crash. I tried to solve this problem by 1. Introducing external delays using loops which didn't help 2. Making the thread switch context by introducing Sleep(0) which did seems to solve the problem (Why?) for this wizard but it crashed another one (again a mistery to me !!) 3. By using Event synchronization objec
-
Hi, I am currently working on a legacy MultiThreaded MFC application which talks to the remote hardware over a network. The application is compiled with VC++ 6.0 SP5 and has many dlls (Regular, Extension, C++ and WIN32). Now here is a typical user scenarion 1. The user starts a wizard to generate a report for a particular parameter usage on the remote hardware. 2. Configures the report parameters through wizard walkthrough and creates a task that will send some commands to the remote hardware and fetch the required data. The task is executed immidiately. Now here is a problem I faced during the recent Release build for internal testing due to accidental change in compiler settings. The application was originally configured to compile with optimization set to "complie for speed" for the Release builds. When the binary created with this setting is executed, the application runs perfectly fine. The user starts the wizard configure parameters create and execute the task. The application fetches the required data and generates the report. Now if the compiler setting is changed to optimization=disable with rest every thing remaining same, the application crashes with bad memory reference during the task execution. During a task execution there may be 3 to 5 threads (worker + GUI) running depending on the complexity of the requested task. I did found out that the crash was due to invalid thread handle value for one of the threads by attaching the VC debugger externally (On running the release build of the application from within the VC debugger, it works perfectly fine, strange !!!???). Breakpoints are not helping as it seems that they introduces enough time delay for the thread handle to be valid. I am not too sure on whether the handle is getting invalid either due to not getting initialized at all (the thread is created externally and then set as a reference in class object) or getting terminated too soon. Well guys I really need help on this as I have been struggling with it for 2-3 days and it is driving me nuts !! 1. I will really like to know what caused the problem at the first place ? 2. What really happened when optimization is turned off that lead to application crash. I tried to solve this problem by 1. Introducing external delays using loops which didn't help 2. Making the thread switch context by introducing Sleep(0) which did seems to solve the problem (Why?) for this wizard but it crashed another one (again a mistery to me !!) 3. By using Event synchronization objec
Hi, it seems to me, that you have some weird problem with thread synchronization somewhere. By changing the optimalization switch, the compiler changed the order/amount of instructions that can changed the order/timing of some operation. This can lead to the situation, where with speed optimalization the thread initialization finishes before other thread uses it, but with optimalization off the initialization is not finished yet, so the second thread uses something uninitialized. By introducing the
Sleep(0)
you changed the order of the instructions stream, so it could 'fix' your issue at the moment. But if the synchronization problem is in your application, it will pop-up somewhere else, so definitiellySleep(0)
is not a conceptual solution for such a problem. By using the event synchronization, you can fix the problem usually (or a part of it). But from the description you gave, it seems that effectivelly you only introduced the 500ms sleep to the start of the application, so just postponing the problem. Only idea I can get is that either the event is not signalled at all, or you can use two different handles, not the same event for synchronization. hope this helps, dont't hesitate to ask for more