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:
- Local() allocates an object of the template argument type using New()
- The destructor calls Delete() on all objects created with Local().
- 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 72 of file vtkSMPThreadLocalObject.h.