// JP opened flex table

Click to See Complete Forum and Search --> : multithreading help


freddy_beer
March 16th, 2004, 08:13 PM
I am writing an aplication with several threads in MFC. For
some of my running functions for threads it woorked just
fine to use Critical Sections. But for others, where I try to update
data on the window (lika a control variable for a ListBox) it crash.
Now, I assume that for these case there should be a patern to follow .... to get an elegant solution for the source code.

thx

Andreas Masur
March 17th, 2004, 05:17 AM
One have to be careful while passing 'CWnd' pointers between threads or applications since the MFC is not thread-safe at object level (only at class level).

As long as the functions do not access the window handle (m_hWnd) you are fine. But many functions need to go back to the specific window handle and then will cause a debug assertion (access vialotion in release mode). The reason is that the window handle maps are kept in thread local storage to ensure protection from simultaneous access from multiple threads. So...there is the possibility for example that one thread might have a mapping from a handle to a C++ object, but another thread might map the same handle to a different one.

Thus you should pass the handle to the dialog and use user-defined messages to update controls etc. For further information take a look at the following FAQ (http://www.codeguru.com/forum/showthread.php?s=&threadid=231250)...

//JP added flex table