[vtk-developers] vtkTimeStamp efficiency

David Gobbi dgobbi at irus.rri.ca
Mon Oct 8 16:39:44 EDT 2001


Hi Christopher,

I haven't made an in-depth study of Mutex vs. CriticalSection vs.
InterlockedIncrement (you might know more about it than I do) but
from my understanding
 1) a Mutex lock is always expensive
 2) a CriticalSection lock is very cheap if it is uncontested (i.e. if
    the lock is available) but is expensive otherwise
 3) an InterlockedIncrement is always very cheap

Where 'cheap' means a few cpu cycles and 'expensive' means hundreds of
cycles.  For the case of vtkTimeStamp where the 'critical section' of
code is so tiny, the InterlockedIncrement is probably not much more
efficient than a CriticalSection (but is certainly far better than
a Mutex).

 - David

--
  David Gobbi, MSc                       dgobbi at irus.rri.ca
  Advanced Imaging Research Group
  Robarts Research Institute, University of Western Ontario

On Mon, 8 Oct 2001, Volpe, Christopher R (CRD) wrote:

>
>
> > -----Original Message-----
> > From: David Gobbi [mailto:dgobbi at irus.rri.ca]
> > Sent: Saturday, October 06, 2001 11:30 PM
> > To: vtk-developers at public.kitware.com
> > Subject: [vtk-developers] vtkTimeStamp efficiency
> >
> >
> > Hi all,
> >
> > I've been looking through the Windows SDK docs, and it looks like
> > vtkTimeStamp could be made significantly more efficient on Win32.
> >
> > There is a Win32 API function called "long
> > InterlockedIncrement(long *)"
> > that does specifically what we need, but is reportedly over 100X
> > faster than the worst-case of the EnterCriticalSection() call that
> > is currently done.
>
> 100x?? I certainly believe that about a mutex, which is what vtkTimeStamp used before I added
> vtkCriticalSection, but I didn't think the latter was *that* expensive. However, yes I think
> InterlockedIncrement would be better, and I could have sworn that there was some reason why I didn't
> use that when I changed vtkTimeStamp last time, but I honestly can't remember what that reason was.
>
> >
> > The efficiency could also be improved by moving the body of
> > vtkTimeStamp::Modified() into the .h file and making it an
> > inline function.
> >
> > Any objections to either of these changes?
>
> Both sound good to me.
>
> -Chris
>




More information about the vtk-developers mailing list