# How to terminate the execution of the vtk algorithm when using multiple threads？

**URL:** https://discourse.vtk.org/t/how-to-terminate-the-execution-of-the-vtk-algorithm-when-using-multiple-threads/12506
**Category:** Support
**Created:** [October 19, 2023, 9:31am UTC](https://discourse.vtk.org/t/how-to-terminate-the-execution-of-the-vtk-algorithm-when-using-multiple-threads/12506 "2023-10-19T09:31:26Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Jawanz](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/j/f08c70/32.png) [@Jawanz](https://discourse.vtk.org/u/Jawanz)
#### Post date: [October 19, 2023, 9:31am UTC](https://discourse.vtk.org/t/how-to-terminate-the-execution-of-the-vtk-algorithm-when-using-multiple-threads/12506/1 "2023-10-19T09:31:26Z")

</div>

Hi,there,

At present, I am using some vtk algorithms (the parent classes are vtkAlgorithm classes) to execute the Update function in the child threads. Sometimes, because it takes too long, I need to terminate the execution of the Update, so I called the SetAbortExecute (true) function in the main thread, but it did not end. Does anyone know what happened? The overall pseudo code logic is as follows:

```auto
void childThread(vtkSmartPointer<vtkAlgorithm> pAlgorithm)
{
      // do algorithm
      pAlgorithm ->Update();
}

void mainThread()
{
     vtkSmartPointer<vtkAlgorithm>pAlgorithm=vtkSmartPointer<vtkAlgorithm>:: New();

     // make some settings
     ......

     std::thread(&childThread, pAlgorithm);

     // stop after a period of time 
     ......
     pAlgorithm-> SetAbortExecute (true);
}

```

---

<div class="post-metadata">

### Author: ![lassoan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lassoan/32/50_2.png) [@lassoan](https://discourse.vtk.org/u/lassoan)
#### Post date: [October 19, 2023, 5:59pm UTC](https://discourse.vtk.org/t/how-to-terminate-the-execution-of-the-vtk-algorithm-when-using-multiple-threads/12506/2 "2023-10-19T17:59:31Z")

</div>

The filter has to regularly look at the `AbortExecute` flag and stop itself if requested. If the filter does not check the flag (or not doing it frequently enough) then it can be fixed by modifying the filter.

You can either wait for some funded project to need this fix; or you can fix yourself and send a merge request to VTK gitlab; or you can provide funding for someone else to implement it.
