[Insight-developers] Thread safety and STL containers

Miller, James V (CRD) millerjv@crd.ge.com
Wed, 28 Nov 2001 12:40:05 -0500


The locking only appears to be on memory allocation.  Some of the STL container implementations keep
a pool of memory. The Microsoft version does not seem to use a memory pool for its standard
allocator.  The SGI/HP versions appear to use a memory pool.

So the performance hit should only be on "resize", etc. So "preallocating" the storage in a vector
and using operator[] will be faster than using push_back().



-----Original Message-----
From: Joshua Cates [mailto:cates@cs.utah.edu]
Sent: Wednesday, November 28, 2001 12:33 PM
To: Lorensen, William E (CRD)
Cc: Insight-Developers (E-mail)
Subject: RE: [Insight-developers] Thread safety and STL containers


We should watch how enabling threading affects performance.  For example,
do critical, stl-based container classes like ValarrayImageContainer start
locking on every call to operator[]?  This would negate any benefits of
multithreading.

Josh.

______________________________
 Josh Cates			
 School of Computer Science	
 University of Utah
 Email: cates@cs.utah.edu
 Phone: (801) 587-7697
 URL:   www.cs.utk.edu/~cates


On Wed, 28 Nov 2001, Lorensen, William E (CRD) wrote:

> well... stl is thread safe provided it is built with threading enabled. Turns out, that at least on
> gnu and sgi, a compiler directive _PTHREADS must be defined. Apparently our current build process
> does not do this. For now, Jim defined it in the CMakeLists.txt in the top directory. CMake should
> define this if threading is on. Similar things need to be done for sproc and maybe win32.
> 
> I'll back out the changes I made to your code.
> 
> 
> Bill (and Jim and Wes)
>  
> 
> -----Original Message-----
> From: Joshua Cates [mailto:cates@cs.utah.edu]
> Sent: Wednesday, November 28, 2001 12:01 PM
> To: Lorensen, William E (CRD)
> Cc: Insight-Developers (E-mail)
> Subject: Re: [Insight-developers] Thread safety and STL containers
> 
> 
> Hi Bill,
> 
> This is great news!  Thanks for tracking it down.
> 
> Josh.
> 
> ______________________________
>  Josh Cates			
>  School of Computer Science	
>  University of Utah
>  Email: cates@cs.utah.edu
>  Phone: (801) 587-7697
>  URL:   www.cs.utk.edu/~cates
> 
> 
> On Wed, 28 Nov 2001, Lorensen, William E (CRD) wrote:
> 
> > Folks,
> > I've been trying to track down intermittent crashes in some itk tests. The crashes occurred on
both
> > solaris and sgi.
> > itkCurvatureFlowTest would crash occasionally on multi processors. I tracked the problem dowm to
> the
> > ThreadedCalculateChange method in Common/itkDenseFiniteDifferenceImageFilter. It seemed that the
> > faceList (implemented with the STL list container) was geeting corrupted.
> >  
> > To make a long story (and long day) short, I searched google with
> > gnu stl thread safe
> > which led me to:
> > http://www.sgi.com/tech/stl/thread_safety.html <http://www.sgi.com/tech/stl/thread_safety.html> 
> >  
> > I fixed "the problem" by putting a lock around the push_back method on the list.
> >  
> > So... beware of STL usage in threaded code.
> >  
> > Bill
> >  
> >  
> > _______________________________________________
> > Insight-developers mailing list
> > Insight-developers@public.kitware.com
> > http://public.kitware.com/mailman/listinfo/insight-developers
> > 
> _______________________________________________
> Insight-developers mailing list
> Insight-developers@public.kitware.com
> http://public.kitware.com/mailman/listinfo/insight-developers
> 

_______________________________________________
Insight-developers mailing list
Insight-developers@public.kitware.com
http://public.kitware.com/mailman/listinfo/insight-developers