 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Tassilo J. Klein Guest
|
Posted: Sun Apr 25, 2004 11:20 pm Post subject: TCriticalSection Problem |
|
|
Hi there,
I have a multi-threaded application making calls with Acquire/Release on
an instance of TCriticalSection in order to guarantee mutual exclusion.
Given the situation that my thread is in the midst of an operation just
like calculating something an updating the progress bar. When now the
main thread is calling ->Acquire on the same instance of
TCriticalSection I have a nice deadlock because of updating the progress
bar. Without the progress bar updating everything works nicely. I read
somewhere in the newsgroup that VCL components are not really working
multithreaded. Is there some work around because I really need
to show the status with the progress bar.
Regards,
Tassilo
|
|
| Back to top |
|
 |
Tom Guest
|
Posted: Mon Apr 26, 2004 12:59 am Post subject: Re: TCriticalSection Problem |
|
|
Are you using the TThread::Synchronize-function to do it? The following is
copied out of BCB6 help:
"Synchronize causes the call specified by Method to be executed using the
main VCL thread, thereby avoiding multi-thread conflicts. If you are unsure
whether a method call is thread-safe, call it from within the Synchronize
method to ensure that it executes in the main VCL thread.
Execution of the thread current is suspended while Method executes in the
main VCL thread."
Ie., no locking needed just to move the progress-bar. Here's a sample:
void __fastcall TMyThread::PushTheButton(void)
{
Button1->Click();
}
void __fastcall TMyThread::Execute()
{
...
Synchronize(PushTheButton);
...
}
Regards
Tom
"Tassilo J. Klein" <nospamTJKlein (AT) web (DOT) de> wrote
| Quote: | Hi there,
I have a multi-threaded application making calls with Acquire/Release on
an instance of TCriticalSection in order to guarantee mutual exclusion.
Given the situation that my thread is in the midst of an operation just
like calculating something an updating the progress bar. When now the
main thread is calling ->Acquire on the same instance of
TCriticalSection I have a nice deadlock because of updating the progress
bar. Without the progress bar updating everything works nicely. I read
somewhere in the newsgroup that VCL components are not really working
multithreaded. Is there some work around because I really need
to show the status with the progress bar.
Regards,
Tassilo
|
|
|
| Back to top |
|
 |
Chris Uzdavinis (TeamB) Guest
|
Posted: Mon Apr 26, 2004 1:29 am Post subject: Re: TCriticalSection Problem |
|
|
"Tassilo J. Klein" <nospamTJKlein (AT) web (DOT) de> writes:
| Quote: | Hi there,
I have a multi-threaded application making calls with
Acquire/Release on an instance of TCriticalSection in order to
guarantee mutual exclusion. Given the situation that my thread is in
the midst of an operation just like calculating something an
updating the progress bar. When now the main thread is calling
->Acquire on the same instance of TCriticalSection I have a nice
deadlock because of updating the progress bar. Without the progress
bar updating everything works nicely. I read somewhere in the
newsgroup that VCL components are not really working
multithreaded. Is there some work around because I really need to
show the status with the progress bar.
|
You should only update the VCL from the main thread. To do so, your
worker thread should use Synchronize() and it should use that function
to invoke a function that does NOTHING but update your progress bar.
If you have a thread that holds a lock, and then you use Synchronize
to make the main thread do something, then your worker thread is
waiting for the call in the main thread to finish. The update
function running in the main thread MUST NOT ever acquire the lock.
--
Chris (TeamB);
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|