[vtkusers] VTK in a multi-threaded program

David Cole dlrdave at aol.com
Mon Mar 24 07:56:04 EDT 2014


Unless somebody else replies with better advice, this still stands, to 
the best of my knowledge:

http://vtk.1045678.n5.nabble.com/vtkRenderer-AddActor-tt5721931.html#a5721932

("VTK is not easily usable from multiple threads. So, in general, you 
should restrict access to VTK objects to a single thread in your app, 
or use mutexes to guarantee that only one thread at a time has access 
to VTK objects. And, if you have to pick a thread to restrict the 
access to, use the same one that’s doing all the GUI stuff -- VTK 
rendering has to run in the GUI thread anyhow.")

The "singleton garbage collection mechanism" you mention is not 
vtkSmartPointer-specific: if you don't use smart pointer, then you need 
to call "Delete" manually.... And it is the calls to Delete and/or 
UnRegister which cause the garbage collection to kick in.

Any VTK method call which has any possibility of modifying any VTK 
state, or which renders, or which might create or delete other VTK 
objects, *must* be called from the main gui thread, or accessed through 
a locking mechanism like a mutex in order to be safe.

It's ironic, because VTK filters themselves actually use threads in 
some cases to achieve speed ups... but it is still very much unusable 
for client programs to create and use VTK objects from multiple threads 
themselves.

If something has changed in the last 2 years that I'm not aware of with 
respect to using VTK objects from multiple threads, I do expect 
somebody will chime in here and correct me if I'm wrong.


Good luck,
David C.



More information about the vtkusers mailing list