[vtkusers] VTK in a multi-threaded program

Richard Whitehead richard.whitehead at vivosight.com
Mon Mar 24 08:16:48 EDT 2014


Thanks David.
It seems that I must ensure that VTK is only ever accessed from the main
GUI thread.
If I find this really difficult then I am going to have to pass all VTK
access through some singleton object that "gets ownership of VTK", which
will be rather foul!
Many thanks again for the advice, it's going to give me a real headache
making a scalable program, but at least I know I'm not going crazy.
Richard


On 24 March 2014 11:56, David Cole <dlrdave at aol.com> wrote:

> 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.
>
>


-- 

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


<http://www.vivosight.com/>


Michelson Diagnostics Ltd, 1 Grays Farm Production Village, Grays Farm
Road, Orpington, Kent  BR5 3BD, UK

Registered Office: 3 Shearwater, Maidstone, ME16 0DW.     Registered in
England No. 5732681
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20140324/e6346634/attachment.html>


More information about the vtkusers mailing list