# run the CoProcess function by a separate thread

**URL:** https://discourse.paraview.org/t/run-the-coprocess-function-by-a-separate-thread/5728
**Category:** In Situ Support
**Created:** [November 5, 2020, 3:47pm UTC](https://discourse.paraview.org/t/run-the-coprocess-function-by-a-separate-thread/5728 "2020-11-05T15:47:52Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![zhe](https://discourse.paraview.org/user_avatar/discourse.paraview.org/zhe/32/2196_2.png) [@zhe](https://discourse.paraview.org/u/zhe)
#### Post date: [November 5, 2020, 3:47pm UTC](https://discourse.paraview.org/t/run-the-coprocess-function-by-a-separate-thread/5728/1 "2020-11-05T15:47:52Z")

</div>

Hello,

My in-situ process run well if I compose simulation iteration and CoProcss function in the main thread. But if I tried to run the CoProcss function (data visualization) asynchronously based on a new thread, I got this error message:

```auto
MandelbulbDynamic: .../paraview/VTK/Common/Core/vtkGarbageCollector.cxx:907: static void vtkGarbageCollector::DeferredCollectionPush(): Assertion `vtkGarbageCollectorIsMainThread()' failed.

```

It looks that I need to define the `VTK_USE_PTHREADS` somewhere, but in the vtk documentation (deprecate-vtkconfigure.md), it said that the `VTK_USE_PTHREADS` is deprecated, I’m a little bit confused about it.

Thanks a lot for your help!

---

<div class="post-metadata">

### Author: ![utkarsh.ayachit](https://discourse.paraview.org/user_avatar/discourse.paraview.org/utkarsh.ayachit/32/39_2.png) [@utkarsh.ayachit](https://discourse.paraview.org/u/utkarsh.ayachit)
#### Post date: [November 5, 2020, 3:49pm UTC](https://discourse.paraview.org/t/run-the-coprocess-function-by-a-separate-thread/5728/2 "2020-11-05T15:49:59Z")

</div>

this is not supported. All Catalyst calls should happen from the same thread.

---

<div class="post-metadata">

### Author: ![zhe](https://discourse.paraview.org/user_avatar/discourse.paraview.org/zhe/32/2196_2.png) [@zhe](https://discourse.paraview.org/u/zhe)
#### Post date: [November 5, 2020, 4:00pm UTC](https://discourse.paraview.org/t/run-the-coprocess-function-by-a-separate-thread/5728/3 "2020-11-05T16:00:32Z")

</div>

Thanks a lot for the information!

Are there some reasons for this design consideration? I just thought naively that maybe there are some values to fully utilize the CPU by overlapping the simulation computation with the in-situ tasks on same node.

---

<div class="post-metadata">

### Author: ![utkarsh.ayachit](https://discourse.paraview.org/user_avatar/discourse.paraview.org/utkarsh.ayachit/32/39_2.png) [@utkarsh.ayachit](https://discourse.paraview.org/u/utkarsh.ayachit)
#### Post date: [November 5, 2020, 4:03pm UTC](https://discourse.paraview.org/t/run-the-coprocess-function-by-a-separate-thread/5728/4 "2020-11-05T16:03:19Z")

</div>

You can do that, but make sure all of the catalyst calls are made from the same thread — which need not be the same thread that the simulation is running under.

---

<div class="post-metadata">

### Author: ![zhe](https://discourse.paraview.org/user_avatar/discourse.paraview.org/zhe/32/2196_2.png) [@zhe](https://discourse.paraview.org/u/zhe)
#### Post date: [November 5, 2020, 4:16pm UTC](https://discourse.paraview.org/t/run-the-coprocess-function-by-a-separate-thread/5728/5 "2020-11-05T16:16:55Z")

</div>

Thanks for the reply, and It look that the error message is generated at this step ([https://gitlab.kitware.com/vtk/vtk/-/blob/master/Common/Core/vtkGarbageCollector.cxx#L907](https://gitlab.kitware.com/vtk/vtk/-/blob/master/Common/Core/vtkGarbageCollector.cxx#L907))  
Based on the comment here, it seems that the functions related with the paraview and vtk should be executed by main thread? If I try to do that, should I let the Catalyst run by main thread and let the simulation to run by a new thread? (it might be a little bit unconventional)

---

<div class="post-metadata">

### Author: ![utkarsh.ayachit](https://discourse.paraview.org/user_avatar/discourse.paraview.org/utkarsh.ayachit/32/39_2.png) [@utkarsh.ayachit](https://discourse.paraview.org/u/utkarsh.ayachit)
#### Post date: [November 5, 2020, 4:36pm UTC](https://discourse.paraview.org/t/run-the-coprocess-function-by-a-separate-thread/5728/6 "2020-11-05T16:36:32Z")

</div>

that is a little weird… I do not understand why `vtkGarbageCollector` needs to be the main thread so long as it’s the same thread … try updating the code for now…maybe expose some API to update the main-thread ivar and set that before creating any VTK objects.

---

<div class="post-metadata">

### Author: ![zhe](https://discourse.paraview.org/user_avatar/discourse.paraview.org/zhe/32/2196_2.png) [@zhe](https://discourse.paraview.org/u/zhe)
#### Post date: [November 6, 2020, 2:37am UTC](https://discourse.paraview.org/t/run-the-coprocess-function-by-a-separate-thread/5728/7 "2020-11-06T02:37:43Z")

</div>

Thanks a lot for the information!
