[Insight-developers] Transforms and thread-safety

M Stauffer (V) mstauff at verizon.net
Wed Feb 23 12:52:51 EST 2011


Hi,

I'm working with Brian Avants on the new registration framework, and the
thread-safety of transforms is one of the issues we're facing. From what
we've heard and seen, transforms are not thread-safe, or at least
assumed not to be. I haven't yet looked closely yet at why, but obvious
candidates are the SetParameters function which shouldn't be accessed by
simultaneous threads, and the TransformPoint routines could pose
problems of course.

Does anyone have specific information about the issues with
thread-safety of transforms?

It's looking important to find a way to make them thread-safe if
possible, at least for certain uses such as in ResampleImageFilter, e.g.
just for calling TransformPoint. I'm willing to help.

Currently when ResampleImageFilter is used with multi-threading enabled,
a copy of the assigned transform is made for each thread in
BeforeThreadedGenerateData. This sidesteps any thread-safety issues, of
course. Some preliminary testing suggests the overhead from this copying
is not insignificant, but more importantly, we'll soon be using
DeformationFieldTransforms and BSpline txf's that use large images as
their transformation parameters, and we expect the overhead of copying
them for each thread to be a problem.

Perhaps we could have an IsThreadSafe method that defaults to returning
false in TransformBase, and derived classes that are known to be
thread-safe could override with true. Then routines like
ResampleImageFilter would only have to make copies of a transform if it
says it isn't thread-safe. This might end being more like a
TransformPointIsThreadSafe method, since full thread-safety might not be
possible. This method would say whether a transform's TransformPoint
method is thread-safe, which would be useful for ResampleImageFilter
since that's all it does with the transforms.

As a fallback, we could implement a read-only transform cloning method
where the parameter buffers are shared between copies, if the
thread-safety issues lie more at the heart of Transform.

Thoughts? Thanks.

Cheers,
Michael



More information about the Insight-developers mailing list