Board index » cppbuilder » CriticalSection() ??

CriticalSection() ??


2003-11-21 01:57:36 PM
cppbuilder38
hi there
i m having multiple thread running which are calling some member function of
Main Form without using Synchronize/Critical Section since the member
function does not uses any of the VCL/CLX Components all it does depending
upon certain states display appropriate MessageDlg(..)
which is occasionally giving problem similar to the one when we dont use
Synchronize(..) while accessing VCL members,
eg: "Canvas does not allow drawing"
maybe the root of my problem, lies in not using Synchronize, is it so ?
any suggestion y ??
also can i use TCriticalSection instead of Synchronize(..) i know i could
have tested it myself, but since the bugs appear occasionally(rarely), i
thought it better to ask here also
regards
-Dumboo
 
 

Re:CriticalSection() ??

"Dumboo" < XXXX@XXXXX.COM >wrote in message
Quote
i m having multiple thread running which are calling some member function
of Main Form without using Synchronize/Critical Section since the member
function does not uses any of the VCL/CLX Components all it does
depending upon certain states display appropriate MessageDlg(..)
If the called function is using MessageDlg(), then you must use
Synchronize(). MessageDlg() uses a TForm internally, thus you are using VCL
components, just not your own. Otherwise, change the function to use the
Win32 API function MessageBox() instead, it is thread-safe without needing
Synchronize().
Quote
which is occasionally giving problem similar to the one when we dont
use Synchronize(..) while accessing VCL members,
See above.
Quote
also can i use TCriticalSection instead of Synchronize(..)
Not in this case, no. Critical sections are only useful when all parts of
the code are using them properly. Using a critical section does not change
which thread is used for executing code like Synchronize() does, and the VCL
does not use critical sections when accessing the GUI, so there is
inadequate protection if you try to use your own critical section manually.
They are only useful when you use them to protect your own data from all
threads that try to access it.
Gambit