[Insight-developers] interrupting filter execution

Miller, James V (GE, Research) millerjv at crd.ge.com
Wed Jul 19 10:09:41 EDT 2006


You have to catch the exception in the thread from which it was thrown.
I do not know of a way to have to have exception pass to the main thread.
There is alot code in the MultiThreader class for the SingleMethodExecute
case where a proxy function is used in each thread to call the method
requested to run in that thread.  The proxy method does a try/catch around
the function invocation.  If an exception is catch, (a limited amount of)
information is passed to the calling thread via return values.

Look at MultiThreader::SingleMethodExecute(), MultiThreader::DispatchSingleMethodThread(),
and MultiThreader::SingleMethodProxy().  SingleMethodProxy() is the method
that catches the exception and send information back to the main thread.

Jim

-----Original Message-----
From: insight-developers-bounces+millerjv=crd.ge.com at itk.org
[mailto:insight-developers-bounces+millerjv=crd.ge.com at itk.org]On Behalf
Of Karthik Krishnan
Sent: Wednesday, July 19, 2006 9:40 AM
To: Paul Koshevoy
Cc: insight-developers at itk.org
Subject: Re: [Insight-developers] interrupting filter execution


I think so too. Each thread has its own stack; so it should have its own
exception stack too. So re-throwing it to the caller would be valid only
within the thread.

There must be some place where you do say 
   gaussianFilter->Update();

Could you not add the try/catch block there ? The gaussian filter runs
as a single threaded filter.

--

Also every subfilter's update in a filter that uses a mini-pipeline
should be within such a try catch block, should it not ?

BigFilter::GenerateData()
{
 try { filter1->Update() } catch (ProgressAborted & e) { // Reset
pipeline etc }
 try { filter2->Update() } catch (ProgressAborted & e) { // Reset
pipeline etc }
}

Thanks
-karthik

On Tue, 2006-07-18 at 17:31 -0600, Paul Koshevoy wrote:
> For some reason, I can't catch the exception thrown in ProgressAccumulator.
> 
> I've modified the ProgressAccumulator::ReportProgress as follows:
>   if( m_MiniPipelineFilter->GetAbortGenerateData() )
>     {
>     throw ExceptionObject();
>     }
> 
> 
> It crashes with the following stack trace:
> 
> FIXME: ABORT: DiscreteGaussianImageFilter
> terminate called after throwing an instance of 'itk::ExceptionObject'
>   what():  Unknown:0:
> None
> 
> Program received signal SIGABRT, Aborted.
> [Switching to Thread 1077832032 (LWP 27676)]
> 0x00002aaaacf8b43a in raise () from /lib64/tls/libc.so.6
> (gdb) where 27
> #0  0x00002aaaacf8b43a in raise () from /lib64/tls/libc.so.6
> #1  0x00002aaaacf8c870 in abort () from /lib64/tls/libc.so.6
> #2  0x00002aaaacbb68b0 in __gnu_cxx::__verbose_terminate_handler ()
>    from /usr/lib64/libstdc++.so.6
> #3  0x00002aaaacbb48e6 in __gxx_personality_v0 ()
>    from /usr/lib64/libstdc++.so.6
> #4  0x00002aaaacbb48bd in __gxx_personality_v0 ()
>    from /usr/lib64/libstdc++.so.6
> #5  0x00002aaaace58848 in _Unwind_ForcedUnwind () from /lib64/libgcc_s.so.1
> #6  0x00002aaaace5892b in _Unwind_Resume () from /lib64/libgcc_s.so.1
> #7  0x000000000062ab11 in itk::ProcessObject::UpdateProgress ()
> #8  0x000000000044c569 in
> itk::NeighborhoodOperatorImageFilter<itk::Image<float, 2u>,
> itk::Image<float, 2u>, double>::ThreadedGenerateData (this=0x8670b54,
>     outputRegionForThread=@0x403e43a0, threadId=1077821840)
>     at
> /usr/sci/crcns-data1/InsightToolkit-2.4.1/Code/BasicFilters/itkNeighborhoodOperatorImageFilter.txx:136
> #9  0x00000000004332a1 in itk::ImageSource<itk::Image<float, 2u>
> >::ThreaderCallback (arg=0x6c16)
>     at
> /usr/sci/crcns-data1/InsightToolkit-2.4.1/Code/Common/itkImageSource.txx:273
> #10 0x00000000006222ea in itk::MultiThreader::SingleMethodExecute ()
> #11 0x00000000004331e4 in itk::ImageSource<itk::Image<float, 2u>
> >::GenerateData (this=0xf66770)
>     at
> /usr/sci/crcns-data1/InsightToolkit-2.4.1/Code/Common/itkImageSource.txx:229
> #12 0x000000000062ce5a in itk::ProcessObject::UpdateOutputData ()
> #13 0x000000000062cf3c in itk::ProcessObject::UpdateOutputData ()
> #14 0x000000000044667c in itk::StreamingImageFilter<itk::Image<float,
> 2u>, itk::Image<float, 2u> >::UpdateOutputData (this=0xf67010)
>     at
> /usr/sci/crcns-data1/InsightToolkit-2.4.1/Code/BasicFilters/itkStreamingImageFilter.txx:159
> #15 0x0000000000444a2c in
> itk::DiscreteGaussianImageFilter<itk::Image<float, 2u>,
> itk::Image<float, 2u> >::GenerateData (this=0x6c16)
>     at
> /usr/sci/crcns-data1/InsightToolkit-2.4.1/Code/BasicFilters/itkDiscreteGaussianImageFilter.txx:306
> #16 0x000000000062ce5a in itk::ProcessObject::UpdateOutputData ()
> #17 0x0000000000423e85 in smooth<itk::Image<float, 2u> > (in=0x403e5810,
>     sigma=7.3376495356751903e-317, maximum_error=0.10000000000000001)
>     at common.hxx:987
> #18 0x0000000000424ab6 in shrink<itk::Image<unsigned char, 2u> >
> (in=0x6c1c,
>     shrink_factor=@0xe29ca0, maximum_error=0.10000000000000001)
>     at common.hxx:1006
> #19 0x0000000000424d63 in std_tile<itk::Image<unsigned char, 2u> > (
>     fn_image=0x6c1c <Address 0x6c1c out of bounds>,
> shrink_factor=@0xe29ca0,
>     pixel_spacing=@0xcd74d0, blab=6) at common.hxx:3596
> #20 0x000000000042a114 in ImageLoader::load_mosaic<itk::Image<unsigned
> char, 2u> > (this=0xe29ca0, fn_mosaic=0x0, shrink_factor=@0x403e60a0,
>     mosaic=@0x403e6090, mosaic_mask=@0x42a114) at ImageLoaderDialog.h:119
> #21 0x0000000000413499 in ImageLoader::run (this=0xe29c80)
>     at ImageLoaderDialog.cpp:81
> #22 0x00002aaaac53e833 in QThreadPrivate::start ()
>    from /usr/lib64/libQtCore.so.4
> #23 0x00002aaaac8e8fa5 in start_thread () from /lib64/tls/libpthread.so.0
> #24 0x00002aaaad019cb2 in clone () from /lib64/tls/libc.so.6
> #25 0x0000000000000000 in ?? ()
> #26 0x0000000000000000 in ?? ()
> (More stack frames follow...)
> 
> My guess is I can't catch the exception because it was thrown from a
> different thread than the one that has the try/catch block.
> I have the following try/catch block (it can be seen as frame #20 in the
> stack trace):
> 
>     try
>     {
>       if (load_mosaic<native_image_t>(qPrintable(source_),
>                       shrink_factor_,
>                       mosaic,
>                       mask))
>       {
>     data_ready_ = true;
>     emit statusUpdate(tr("Done "));
>       }
>       else
>       {
>     emit statusUpdate(tr("Aborted "));
>       }
>     }
>     catch (itk::ExceptionObject & exception)
>     {
>       emit statusUpdate(tr(exception.GetDescription()));
>     }
>     catch (...)
>     {
>       emit statusUpdate(tr("FIXME: caught an unrecognized exception"));
>     }
> 
> 
> Karthik Krishnan wrote:
> > Never mind.. I am stupid. Discard the earlier suggestion. The
> > exception must be thrown by the filter, of course.., not you.
> >
> > That exception is also thrown by the filter or the progress reporter
> > in the CompletedPixel method.
> > http://www.itk.org/cgi-bin/viewcvs.cgi/Code/Common/itkProgressReporter.cxx?rev=1.8&root=Insight&view=markup
> >
> >
> > It should likewise be thrown also in the
> > ProgressAccumulator.cxx::ReportProgress method as in
> > if (m_MiniPipelineFilter->GetAbortGenerateData())
> >  {
> >   throw ProgressAborted();
> >  }
> >
> > That addition should fix it, I suppose. Could you check ?
> >
> > Thanks
> > -karthik
> >
> 
> _______________________________________________
> Insight-developers mailing list
> Insight-developers at itk.org
> http://www.itk.org/mailman/listinfo/insight-developers

_______________________________________________
Insight-developers mailing list
Insight-developers at itk.org
http://www.itk.org/mailman/listinfo/insight-developers


More information about the Insight-developers mailing list