BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

TCriticalSection Problem

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Usage)
View previous topic :: View next topic  
Author Message
Tassilo J. Klein
Guest





PostPosted: Sun Apr 25, 2004 11:20 pm    Post subject: TCriticalSection Problem Reply with 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
Tom
Guest





PostPosted: Mon Apr 26, 2004 12:59 am    Post subject: Re: TCriticalSection Problem Reply with quote



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





PostPosted: Mon Apr 26, 2004 1:29 am    Post subject: Re: TCriticalSection Problem Reply with quote



"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
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Usage) All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.