[vtkusers] Multithreading

Daniel Lüken d.lueken at stud.fh-dortmund.de
Tue May 8 12:44:55 EDT 2007


Hello,

I'm using VTK 5 statically linked into a C++ Win32 application.

My problem is, that I can't get it to work across multiple threads. There's 
always just 1 thread working with a vtkRenderWindow, so general 
thread-safety shouldn't be a problem. (If I'm not mistaken, there's even 
just 1 thread working with any vtk function at any given time.)
My first attempt was to create and destroy my vtk rendering environments in 
the main thread and handle new incoming data in another thread, which called 
Render() after updating the data and performing the necessary operations. 
(Which would just be updating the debug text in a vtkTextActor as of yet.) 
That attempt failed on the Render() call, stating that wglMakeCurrent() 
failed.
My 2nd attempt was to replace the Render() call with an InvalidateRect() 
call on the window containing the render context, but then another vtk 
render window didn't react anymore, except if I added a Sleep(1) after 
InvalidateRect() (I wonder why that seems to work. Sleep(0) won't and the 
reaction doesn't slow down compared to a Sleep(5000)).
My 3rd attempt was to put the initialization and deletion of the vtk 
rendering environments for my visualization windows into the thread that 
handles the updates of newly incoming data, which resulted in a sudden halt 
of the main thread, even though I didn't use any kind of locks.

I will have to update my data in another thread, because it constantly has 
to check for new input and update the visualizations, which would keep my 
main thread from returning to the message loop, which is kind of 
undesirable.

Any ideas?

D. Lüken 




More information about the vtkusers mailing list