From 08bc946edce014ce98dc937d137b1b3b3015d71a Mon Sep 17 00:00:00 2001 From: Bradley Lowekamp Date: Mon, 25 Nov 2024 09:52:10 -0500 Subject: [PATCH] BUG: Address race condition with threaded copying input to output Move copying input to output to before threaded methods, to ensure the operation has been completed before modifications. --- .../itkObjectMorphologyImageFilter.hxx | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/Modules/Filtering/BinaryMathematicalMorphology/include/itkObjectMorphologyImageFilter.hxx b/Modules/Filtering/BinaryMathematicalMorphology/include/itkObjectMorphologyImageFilter.hxx index e5d3e1e37e8..67d0dee6ba0 100644 --- a/Modules/Filtering/BinaryMathematicalMorphology/include/itkObjectMorphologyImageFilter.hxx +++ b/Modules/Filtering/BinaryMathematicalMorphology/include/itkObjectMorphologyImageFilter.hxx @@ -100,17 +100,11 @@ ObjectMorphologyImageFilter::BeforeThreadedG { this->GetOutput()->FillBuffer(0); } -} -template -void -ObjectMorphologyImageFilter::DynamicThreadedGenerateData( - const OutputImageRegionType & outputRegionForThread) -{ - ImageRegionConstIterator iRegIter; - ImageRegionIterator oRegIter; - iRegIter = ImageRegionConstIterator(this->GetInput(), outputRegionForThread); - oRegIter = ImageRegionIterator(this->GetOutput(), outputRegionForThread); + RegionType requestedRegion = this->GetOutput()->GetRequestedRegion(); + + auto iRegIter = ImageRegionConstIterator(this->GetInput(), requestedRegion); + auto oRegIter = ImageRegionIterator(this->GetOutput(), requestedRegion); /* Copy the input image to the output image - then only boundary pixels * need to be changed in the output image */ while (!oRegIter.IsAtEnd()) @@ -122,7 +116,14 @@ ObjectMorphologyImageFilter::DynamicThreaded ++oRegIter; ++iRegIter; } +} + +template +void +ObjectMorphologyImageFilter::DynamicThreadedGenerateData( + const OutputImageRegionType & outputRegionForThread) +{ // Find the boundary "faces" NeighborhoodAlgorithm::ImageBoundaryFacesCalculator fC; typename NeighborhoodAlgorithm::ImageBoundaryFacesCalculator::FaceListType faceList =