[Insight-developers] Thread safety and STL containers

Lorensen, William E (CRD) lorensen@crd.ge.com
Wed, 28 Nov 2001 12:21:44 -0500


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
>