[vtkusers] VTK in a multi-threaded program

Richard Whitehead richard.whitehead at vivosight.com
Sat Mar 22 07:45:30 EDT 2014


I hope that some expert can offer their advice...
I'm trying to use VTK in a program that is multi-threaded at a fairly
coarse level - for example it has threads doing visualisation, others
saving data in the background.  I understand that VTK is not thread-safe,
and so I would expect to follow the usual rules for using classes that are
not thread-safe: only access each object from one thread, and use mutexes
to protect any global or static data.
But it seems that even applying these rules I am running into problems with
VTK.  Certainly I can't use vtkSmartPointer, because it accesses a
singleton garbage collection mechanism.  I tried making a mutex-protected
version of vtkSmartPointer but still had memory corruptions, and I think
what is happening is that inside VTK when objects are being created and
destroyed, some static or singleton data is being accessed.
So for instance if I create two filters, each in a different thread, use
them in their own threads and destroy them in their own threads, I still
seem to get strange errors that I don't get in a single-threaded version of
the program, presumably because the filter is creating its own temporary
objects via some internal memory management system that is not thread-safe.
Can anyone offer any advice?  Is VTK simply unusable in a multi-threaded
program?  Any serious application program (not research tool) is going to
be multi-threaded, surely others must have addressed this issue?
Any help very gratefully received.
Richard


Richard Whitehead *-* Senior Imaging Engineer

*Michelson Diagnostics Ltd*

*M:* +44 (0)7905 955276   *T:* +44 (0)20 8308 1695

*E: *richard.whitehead at vivosight.com   *W:* www.vivosight.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20140322/c12a6cc9/attachment.html>


More information about the vtkusers mailing list