VTK
Classes | Public Member Functions | List of all members
vtkSMPThreadLocalObject< T > Class Template Reference

Thread local storage for VTK objects. More...

#include <vtkSMPThreadLocalObject.h>

Inheritance diagram for vtkSMPThreadLocalObject< T >:
[legend]

Classes

class  iterator
 Subset of the standard iterator API. More...
 

Public Member Functions

 vtkSMPThreadLocalObject ()
 Default constructor. More...
 
 vtkSMPThreadLocalObject (T *const &exemplar)
 
virtual ~vtkSMPThreadLocalObject ()
 
T *& Local ()
 Returns an object local to the current thread. More...
 
size_t size () const
 Return the number of thread local objects that have been initialized. More...
 
iterator begin ()
 
iterator end ()
 

Detailed Description

template<typename T>
class vtkSMPThreadLocalObject< T >

Thread local storage for VTK objects.

This class essentially does the same thing as vtkSMPThreadLocal with 2 additional functions:

Warning
There is absolutely no guarantee to the order in which the local objects will be stored and hence the order in which they will be traversed when using iterators. You should not even assume that two vtkSMPThreadLocal populated in the same parallel section will be populated in the same order. For example, consider the following
* vtkSMPThreadLocal<int> Foo;
* vtkSMPThreadLocal<int> Bar;
* class AFunctor
* {
*    void Initialize() const
*    {
*      int& foo = Foo.Local();
*      int& bar = Bar.Local();
*      foo = random();
*      bar = foo;
*    }
*
* @warning
*    void operator()(vtkIdType, vtkIdType)
*    {}
*    void Finalize()
*    {}
* };
*
* @warning
* AFunctor functor;
* vtkSMPTools::For(0, 100000, functor);
*
* @warning
* vtkSMPThreadLocal<int>::iterator itr1 = Foo.begin();
* vtkSMPThreadLocal<int>::iterator itr2 = Bar.begin();
* while (itr1 != Foo.end())
* {
*   assert(*itr1 == *itr2);
*   ++itr1; ++itr2;
* }
* 
It is possible and likely that the assert() will fail using the TBB backend. So if you need to store values related to each other and iterate over them together, use a struct or class to group them together and use a thread local of that class.
See also
vtkSMPThreadLocal
Tests:
vtkSMPThreadLocalObject (Tests)

Definition at line 83 of file vtkSMPThreadLocalObject.h.

Constructor & Destructor Documentation

◆ vtkSMPThreadLocalObject() [1/2]

template<typename T>
vtkSMPThreadLocalObject< T >::vtkSMPThreadLocalObject ( )
inline

Default constructor.

Definition at line 97 of file vtkSMPThreadLocalObject.h.

◆ vtkSMPThreadLocalObject() [2/2]

template<typename T>
vtkSMPThreadLocalObject< T >::vtkSMPThreadLocalObject ( T *const &  exemplar)
inline

Definition at line 101 of file vtkSMPThreadLocalObject.h.

◆ ~vtkSMPThreadLocalObject()

template<typename T>
virtual vtkSMPThreadLocalObject< T >::~vtkSMPThreadLocalObject ( )
inlinevirtual

Definition at line 105 of file vtkSMPThreadLocalObject.h.

Member Function Documentation

◆ Local()

template<typename T>
T*& vtkSMPThreadLocalObject< T >::Local ( )
inline

Returns an object local to the current thread.

This object is allocated with ::New() and will be deleted in the destructor of vtkSMPThreadLocalObject.

Definition at line 124 of file vtkSMPThreadLocalObject.h.

◆ size()

template<typename T>
size_t vtkSMPThreadLocalObject< T >::size ( ) const
inline

Return the number of thread local objects that have been initialized.

Definition at line 145 of file vtkSMPThreadLocalObject.h.

◆ begin()

template<typename T>
iterator vtkSMPThreadLocalObject< T >::begin ( )
inline

Definition at line 200 of file vtkSMPThreadLocalObject.h.

◆ end()

template<typename T>
iterator vtkSMPThreadLocalObject< T >::end ( )
inline

Definition at line 207 of file vtkSMPThreadLocalObject.h.


The documentation for this class was generated from the following file: