Board index » cppbuilder » My thread dies at TRichEdit1->Lines->Append()

My thread dies at TRichEdit1->Lines->Append()


2004-10-02 10:48:43 AM
cppbuilder50
Hi, group!. I am logging events to a TRichEdit component. But sometimes the thread that executes this:
Richedit->lines->append()
dies. Can anybody help me with this? My software is heavily logging, about 1MB/min.
I can show some portions of the code, as well as the general design of the logging system.
Thanx!
 
 

Re:My thread dies at TRichEdit1->Lines->Append()

"eduardo" < XXXX@XXXXX.COM >wrote in message
Quote
Hi, group!. I am logging events to a TRichEdit component. But
sometimes the thread that executes this:

Richedit->lines->append()

dies.
Please be more specific. When you say "thread", are you referring to a
worker thread? If so, are you providing adequate synching to access the
RichEdit in a thread-safe manner?
Quote
I can show some portions of the code
Please do so.
Gambit
 

Re:My thread dies at TRichEdit1->Lines->Append()

"eduardo" < XXXX@XXXXX.COM >writes:
Quote
Hi, group!. I am logging events to a TRichEdit component. But
sometimes the thread that executes this:
Richedit->lines->append()
dies.
There is only one thread that can interact with VCL objects, and
that's the MAIN thread. If you're doing the above append call from
any other thread, no matter how much locking you do, your code is
inherently broken.
Quote
Can anybody help me with this? My software is heavily logging, about
1MB/min.
If you're going to log for a multi-threaded program, you'll either
synchronize your calls to log (which isn't good for performance), or
log to something that isn't a VCL object. Those are the only options
I see.
--
Chris (TeamB);
 

{smallsort}

Re:My thread dies at TRichEdit1->Lines->Append()

Hi!
Chris Uzdavinis (TeamB) wrote:
Quote
There is only one thread that can interact with VCL objects, and
that's the MAIN thread. If you're doing the above append call from
any other thread, no matter how much locking you do, your code is
inherently broken.
Does this also hold true for non-visual components as
TStringList? I mean, if I have a thread which creates its own
TStringList object, may this be accessed from within the thread
and without Synchronize(...)?
Frank
 

Re:My thread dies at TRichEdit1->Lines->Append()

Chris Uzdavinis (TeamB) < XXXX@XXXXX.COM >wrote:
Quote
"eduardo" < XXXX@XXXXX.COM >writes:

>Hi, group!. I am logging events to a TRichEdit component. But
>sometimes the thread that executes this:

>Richedit->lines->append()

>dies.

There is only one thread that can interact with VCL objects, and
that's the MAIN thread. If you're doing the above append call from
any other thread, no matter how much locking you do, your code is
inherently broken.

>Can anybody help me with this? My software is heavily logging, about
>1MB/min.

If you're going to log for a multi-threaded program, you'll either
synchronize your calls to log (which isn't good for performance), or
log to something that isn't a VCL object. Those are the only options
I see.

--
Chris (TeamB);
 

Re:My thread dies at TRichEdit1->Lines->Append()

Frank Birbacher < XXXX@XXXXX.COM >writes:
Quote
Hi!

Chris Uzdavinis (TeamB) wrote:
>There is only one thread that can interact with VCL objects, and
>that's the MAIN thread. If you're doing the above append call from
>any other thread, no matter how much locking you do, your code is
>inherently broken.

Does this also hold true for non-visual components as TStringList? I
mean, if I have a thread which creates its own TStringList object, may
this be accessed from within the thread and without Synchronize(...)?
Probably, but then again, I really don't know. I tend to prefer
erring on the side of caution. Doing tricky things in threads that
make use of subtlties of the VCL just doesn't sound fun to me. :)
--
Chris (TeamB);
 

Re:My thread dies at TRichEdit1->Lines->Append()

"Frank Birbacher" < XXXX@XXXXX.COM >wrote in message
Quote
Does this also hold true for non-visual components as TStringList?
if I have a thread which creates its own TStringList object, may
this be accessed from within the thread and without Synchronize(...)?
If the owning thread is the only thread that is accessing the TStringList,
then you do not need any synchronization at all. Otherwise, if you are
sharing the TStringList across threads then you should provide some kind of
synchronization for it. You don't need Synchronize() for that, though, a
mutex or critical section will work fine instead.
Gambit
 

Re:My thread dies at TRichEdit1->Lines->Append()

Sorry about that "comment only" post. Something went wrong.
I've created a new thread object (LogWriterThread) that uses the synchronize() call to write to the richedit. This thread receives messages thru the write(ansistring) method. But now I have to use an instance variable (AnsiString aux) to be able to tell the synchronized method what to append():
::execute
...
// read from buffers filled by write(ansistring)
aux = buffer at next not-yet-written position
Synchronize(postMsg);
....
void __fastcall X::postMsg(void)
{
RichEdit->Lins->append(aux)
// aux is my instance variable
}
Is this scheme broken?
Thanks in advance, TeamB!!
Chris Uzdavinis (TeamB) < XXXX@XXXXX.COM >wrote:
Quote
"eduardo" < XXXX@XXXXX.COM >writes:

>Hi, group!. I am logging events to a TRichEdit component. But
>sometimes the thread that executes this:

>Richedit->lines->append()

>dies.

There is only one thread that can interact with VCL objects, and
that's the MAIN thread. If you're doing the above append call from
any other thread, no matter how much locking you do, your code is
inherently broken.

>Can anybody help me with this? My software is heavily logging, about
>1MB/min.

If you're going to log for a multi-threaded program, you'll either
synchronize your calls to log (which isn't good for performance), or
log to something that isn't a VCL object. Those are the only options
I see.

--
Chris (TeamB);
 

Re:My thread dies at TRichEdit1->Lines->Append()

"eduardo" < XXXX@XXXXX.COM >writes:
Quote
Sorry about that "comment only" post. Something went wrong.

I've created a new thread object (LogWriterThread) that uses the
synchronize() call to write to the richedit. This thread receives
messages thru the write(ansistring) method. But now I have to use an
instance variable (AnsiString aux) to be able to tell the
synchronized method what to append():
I wouldn't call your design "broken" but could be improved, to help
ensure that nothing changes between your call to synchronize and when
it uses your member data.
Here's an article I recently wrote about this that should give you a
good idea of how to make this cleaner:
tinyurl.com/5bplu
which expands to:
groups.google.com/groups&lr=&ie=UTF-8&selm=j5vfdyl2di.fsf%40explicit.atdesk.com&rnum=1
Is this what you're looking for?
--
Chris (TeamB);
 

Re:My thread dies at TRichEdit1->Lines->Append()

Chris Uzdavinis (TeamB) < XXXX@XXXXX.COM >wrote:
Quote
"eduardo" < XXXX@XXXXX.COM >writes:

>Sorry about that "comment only" post. Something went wrong.
>
>I've created a new thread object (LogWriterThread) that uses the
>synchronize() call to write to the richedit. This thread receives
>messages thru the write(ansistring) method. But now I have to use an
>instance variable (AnsiString aux) to be able to tell the
>synchronized method what to append():

I wouldn't call your design "broken" but could be improved, to help
ensure that nothing changes between your call to synchronize and when
it uses your member data.
In current code, I have completely controlled the access to the member data in cuestion. However, the article below is most useful when the code is more complex.
Quote

Here's an article I recently wrote about this that should give you a
good idea of how to make this cleaner:

tinyurl.com/5bplu

which expands to:
groups.google.com/groups&lr=&ie=UTF-8&selm=j5vfdyl2di.fsf%40explicit.atdesk.com&rnum=1


Is this what you're looking for?
Yes, its very helpful. You encapsulate the request in an add-hoc object. I think I have things clearer now.
Thank you.
Eduardo