VTK
|
A simple thread local implementation for sequential operations. More...
#include <vtkSMPThreadLocal.h>
Classes | |
class | iterator |
Public Member Functions | |
vtkSMPThreadLocal () | |
vtkSMPThreadLocal (const T &exemplar) | |
T & | Local () |
size_t | size () const |
iterator | begin () |
iterator | end () |
A simple thread local implementation for sequential operations.
A thread local object is one that maintains a copy of an object of the template type for each thread that processes data. vtkSMPThreadLocal creates storage for all threads but the actual objects are created the first time Local() is called. Note that some of the vtkSMPThreadLocal API is not thread safe. It can be safely used in a multi-threaded environment because Local() returns storage specific to a particular thread, which by default will be accessed sequentially. It is also thread-safe to iterate over vtkSMPThreadLocal as long as each thread creates its own iterator and does not change any of the thread local objects.
A common design pattern in using a thread local storage object is to write/accumulate data to local object when executing in parallel and then having a sequential code block that iterates over the whole storage using the iterators to do the final accumulation.
Note that this particular implementation is designed to work in sequential mode and supports only 1 thread.
Definition at line 52 of file vtkSMPThreadLocal.h.
vtkSMPThreadLocal< T >::vtkSMPThreadLocal | ( | ) | [inline] |
Default constructor. Creates a default exemplar.
Definition at line 59 of file vtkSMPThreadLocal.h.
vtkSMPThreadLocal< T >::vtkSMPThreadLocal | ( | const T & | exemplar | ) | [inline] |
Constructor that allows the specification of an exemplar object which is used when constructing objects when Local() is first called. Note that a copy of the exemplar is created using its copy constructor.
Definition at line 69 of file vtkSMPThreadLocal.h.
T& vtkSMPThreadLocal< T >::Local | ( | ) | [inline] |
Returns an object of type T that is local to the current thread. This needs to be called mainly within a threaded execution path. It will create a new object (local to the tread so each thread get their own when calling Local) which is a copy of exemplar as passed to the constructor (or a default object if no exemplar was provided) the first time it is called. After the first time, it will return the same object.
Definition at line 83 of file vtkSMPThreadLocal.h.
size_t vtkSMPThreadLocal< T >::size | ( | ) | const [inline] |
Return the number of thread local objects that have been initialized
Definition at line 98 of file vtkSMPThreadLocal.h.
iterator vtkSMPThreadLocal< T >::begin | ( | ) | [inline] |
Returns a new iterator pointing to the beginning of the local storage container. Thread safe.
Definition at line 170 of file vtkSMPThreadLocal.h.
iterator vtkSMPThreadLocal< T >::end | ( | ) | [inline] |
Returns a new iterator pointing to past the end of the local storage container. Thread safe.
Definition at line 199 of file vtkSMPThreadLocal.h.