Skip to content

davidtgillard/vtk_tcl_thread_util

Repository files navigation

vtk_tcl_thread_util

Provides a Tcl package that includes a single function to enable passing vtkObject handles between Tcl threads.

usage

The package vtk_tcl_thread_util provides a single function:

vtk_tcl_thread_util::register_vtk_object threadid vtk_obj ?name?

This can be used to register the vtk object command vtk_obj with the interpreter of thread threadid. The resulting name of the object in the thread is returned, which can be either specified with name, or autogenerated. In the case where vtk_obj has previously been registered in the interpreter of threadid, and name is not specified, then it's previous name will be returned.

An example:

package require vtk_tcl_thread_util

set obj [vtkObject New]; # init a VTK object
set t [thread::create {package require vtk_tcl_thread_util; thread::wait}]; # spawn a thread
set t_obj [vtk_tcl_thread_util::register_vtk_object $t $obj]; # t_obj now holds the name of the object in the spawned thread

Note that the refcount of the object is incremented whenever it is successfully registered with a new thread. This should ensure that the memory of the underlying VTK object will be freed only when it is released from all threads.

Do be careful - VTK itself is not thread-safe in general.

About

An simple function for passing vtkObject handles between Tcl threads.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published