Board index » cppbuilder » Re: all BCB6 apps: memory corruption in hyperthreading / dualCPU machines

Re: all BCB6 apps: memory corruption in hyperthreading / dualCPU machines


2005-10-26 01:11:40 AM
cppbuilder43
Zach Saw wrote:
Quote
>How about via the DataSet object?


As I've said, they're independent.
You earlier wrote:
with that, I create 8 threads, and run DataSet->Open() and
DataSet->Close() over and over again.
Could you clarify that? It's still not clear whether you are doing
something which one might reasonably expect requires synchronization,
such as using a copies of an AnsiString in multiple threads (with the
associated copy on write problems), etc.
Tom
 
 

Re:Re: all BCB6 apps: memory corruption in hyperthreading / dualCPU machines

Jonathan Benedicto wrote:
Quote
Zach Saw wrote:

>nope. like i've said before, the threads are completely unaware of
>the rest.


I seems to be impossible for threading to cause problems with AnsiStrings
as long as the strings are never access by different threads.
But they are reference counted, so if you access apparently independent
copies of the same string in multiple threads, you might have a problem.
Calling Unique() after making the copy might solve the problem.
Tom
 

Re:Re: all BCB6 apps: memory corruption in hyperthreading / dualCPU machines

"Zach Saw" < XXXX@XXXXX.COM >wrote in message
Quote
I'm not writing to the global variable except in the GUI (TForm c'tor)...
That depends on how you are reading it. Certain reading operations can
internally alter the contents of the AnsiString without you knowing it.
In any case, when sharing a global across threads, especially a data type
that is not a POD type (integers, booleans, etc) then you should ALWAYS
serialize access to it.
Gambit
 

{smallsort}

Re:Re: all BCB6 apps: memory corruption in hyperthreading / dualCPU machines

Tom Widmer wrote:
Quote
But they are reference counted, so if you access apparently
independent copies of the same string in multiple threads, you might
have a problem. Calling Unique() after making the copy might solve
the problem.
What I was asking is whether the strings where ever copied/shared etc,
among several threads, just to make sure.
Jonathan
 

Re:Re: all BCB6 apps: memory corruption in hyperthreading / dualCPU machines

well, each thread has its own DataSet -- so I'm only opening and closing the
dataset in their own threads... so there're no sharing of AnsiString across
threads, unless the code in VCL tries to be funny... :)
"Tom Widmer" < XXXX@XXXXX.COM >wrote in message
Quote
Zach Saw wrote:
>>How about via the DataSet object?
>
>
>As I've said, they're independent.

You earlier wrote:
with that, I create 8 threads, and run DataSet->Open() and
DataSet->Close() over and over again.

Could you clarify that? It's still not clear whether you are doing
something which one might reasonably expect requires synchronization, such
as using a copies of an AnsiString in multiple threads (with the
associated copy on write problems), etc.

Tom
 

Re:Re: all BCB6 apps: memory corruption in hyperthreading / dualCPU machines

the global variable is of type integer...
"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >wrote in message
Quote

"Zach Saw" < XXXX@XXXXX.COM >wrote in message
news:435e38c6$ XXXX@XXXXX.COM ...

>I'm not writing to the global variable except in the GUI (TForm c'tor)...

That depends on how you are reading it. Certain reading operations can
internally alter the contents of the AnsiString without you knowing it.

In any case, when sharing a global across threads, especially a data type
that is not a POD type (integers, booleans, etc) then you should ALWAYS
serialize access to it.


Gambit


 

Re:Re: all BCB6 apps: memory corruption in hyperthreading / dualCPU machines

"Zach Saw" < XXXX@XXXXX.COM >wrote in message
Quote
the global variable is of type integer...
Even an integer needs to be serialized to protect it when multiple threads
are accessing it at the same time.
Gambit
 

Re:Re: all BCB6 apps: memory corruption in hyperthreading / dualCPU machines

yeah, but there's nothing writing to the global var...
it's there just for testing memory corruption -- to see if the value it is
initialized with is still the same at the end of the test program :)
"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >wrote in message
Quote

"Zach Saw" < XXXX@XXXXX.COM >wrote in message
news: XXXX@XXXXX.COM ...

>the global variable is of type integer...

Even an integer needs to be serialized to protect it when multiple threads
are accessing it at the same time.


Gambit


 

Re:Re: all BCB6 apps: memory corruption in hyperthreading / dualCPU machines

Tom Widmer < XXXX@XXXXX.COM >writes:
Quote
But they are reference counted, so if you access apparently
independent copies of the same string in multiple threads, you might
have a problem. Calling Unique() after making the copy might solve the
problem.
Without a lock, even that is insufficient. Two seperate threads could
both call Unique at the same time, and both modify the same original
string, possibly messing up its refcount.
--
Chris (TeamB);