[Insight-developers] itkTimeStamp Test Failures Mistery

Sean McBride sean at rogue-research.com
Thu Feb 19 14:40:48 EST 2009


On 2/19/09 8:06 PM, Tom Vercauteren said:

>When several threads assign the same integer variable at the same
>time, is it possible that the value of the integer be corrupted or can
>we safely assume that the value of the integer will be one of those
>trying to be assigned by the threads?

I don't think C/C++ make any such guarantee.  However, I believe 'in the
real world', it's a pretty safe assumption.  This was actually discussed
recently on another list:

<http://lists.apple.com/archives/objc-language/2009/Feb/msg00028.html>

"Ordinary assignment (of pointer-aligned pointer-size values) is a
single instruction on any practical CPU architecture. That assignment is
atomic with respect to simultaneous read (pointer-size pointer- aligned)
of that same memory location. That is, the reader will always get either
the old value or the new value, never something half-and- half or random."

>If we go for thread-safe, we need to modify the TimeStamp
>optimization.

How different is performance using the mutex instead of the 'optimised'
version?  ie: do we need the optimised version at all?

-- 
____________________________________________________________
Sean McBride, B. Eng                 sean at rogue-research.com
Rogue Research                        www.rogue-research.com 
Mac Software Developer              Montréal, Québec, Canada




More information about the Insight-developers mailing list