How to use VTK in multi-threaded context?
In some examples where VTK can be used along with OpenGL and GLEW (using vtkOpenGLRenderWindow
or vtkVRRenderWindow
for instance), my understanding is that, depending on cases, you’ll have to handle by yourself (as VTK is used in some kind of external window and no more in it’s native viewer) up to 3 major problematics:
- rendering
- propagate events to interactor and interactor style (dispatch) to move into the scene
- modify the scene (actors or filters for instance)
Say 1 and 2 are handled by the main thread, and, 3 is handled by a concurrent thread (spawned by the main thread).
I understand VTK is not thread-safe: https://vtk.org/pipermail/vtkusers/2015-September/092326.html. Using mutex to “lock” the scene between 1 and 3 make sense: you should not modify/render what you render/modify.
Questions:
- Is mutex needed also for 2 or is this part guaranteed to be thread-safe? (such that using mutex for 2 would be overkill and degrades performance)
- What is the best practice recommended? Is mutex a good choice or are there better ways?