LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Is InstallPopup not threadsafe?

I sometimes see my Apps fail with a c0000005 GPF. Dr. Watson lists a stack backtrace like

0012fdb8 686433a1 00fa35b0 00000001 00000001 cvirte!MinimizeAllWindows+0x3fb4
0012fe34 6863c3b4 00000000 00000a28 685f76c6 cvirte!MinimizeAllWindows+0x5fc6
0012fe60 685f7896 0000002a 00000000 0012fe80 cvirte!SetWindowsErrorMode+0x1b3b
0012fe8c 685f78e6 0000002a 00000000 00000001 cvirte!InstallPopupPanel+0x2b
0012feac 006e1e66 0000002a 00000000 001b00f8 cvirte!InstallPopup+0x2a

I managed to create a test programm which fails the same way (code attached)

Within CVI-IDE, the program freezes within InstallPopup() but if I run the exe, it produces the GPF.

I did this with CVI 8.5 IDE/runtime, but older versions sometimes showed the same crash.
-----------------------
/* Nothing past this point should fail if the code is working as intended */
0 Kudos
Message 1 of 3
(3,437 Views)

Hello CVI-User,

All UI functions are supposed to be thread-safe.

Having said that, I did run your program and was able to reproduce the crash. After some investigation, I was able to find the underlying bug in the CVI runt-time engine that is causing this crash. We'll fix this bug in the next version. Unfortunately, there is no good way that I can think of for you modify your program in order to avoid this bug. The bug can happen when you set or unset the modality of a panel from a secondary thread.

The longer explanation for the bug is as follows:

The UI library implements its thread-safety, for the most part, by locking all functions and event processing at the highest possible level of the API. This ensures that at any one time, only one thread is active inside a UI function. That is the theory. In practice, things are a bit more complicated. Because there are a number of Windows system calls that result in messages being sent to other threads, in order to avoid deadlocks, the global UI lock sometimes has to be temporarily relinquished, which can allow another waiting thread to enter a UI function. When this happens, a "hole" is created, and special code needs to be written to patch up this hole manually. Unfortunately, you've run into a hole that hadn't been detected before, and therefore hadn't been patched. What is happening internally is that the main (RunUserInteface) thread, in response to an application activation message, is relinquishing a lock around a required low-level operation on one of the two windows that belong to the thread functions. Sometimes, when that lock is relinquished, one of the the other threads enters the HidePanel function. Normally that would be a harmless operation, but when the panel is modal (created via InstallPopup), that requires the panel's window to be replaced (destroyed and recreated). When the timing is really bad, the old window is destroyed just before the main thread tries to access it, and the crash ensues.

Let me know if you have any other questions.

Message 2 of 3
(3,416 Views)
The longer explanation is very much appreciated.  Thanks!
0 Kudos
Message 3 of 3
(3,348 Views)