#include <ThreadLocal.h>
Inheritance diagram for ZThread::ThreadLocal::
Public Methods | |
ThreadLocal () throw () | |
virtual | ~ThreadLocal () throw () |
T | get () const throw (Synchronization_Exception) |
T | set (T val) const throw (Synchronization_Exception) |
Protected Methods | |
virtual void* | initialValue (void *initValue) throw () |
virtual bool | propogateValue () throw () |
The first time a ThreadLocal veriable is accessed by a thread the initialValue() method will be invoked. This allows subclasses to perfrom any special actions they might need to when a new thread uses one of these variables.
The recommended usage of this object would be something like in the example shown below
class MyClass { protected: static ThreadLocal<int> _threadKey; public: int getValue() const { return _threadKey.get(); } int setValue(int n) const { return _threadKey.set(n); } };
The ThreadLocal object itself acts as the key, instead of some arbitrary integer that needed to be defined by the programmer before. This is a much more elegant solution.
|
Create a new ThreadLocal object |
|
Destroy this ThreadLocal object |
|
Get a value with this ThreadLocal object. Any value retrieved from this object will have been set from the same Thread.
Reimplemented from ZThread::AbstractThreadLocal. |
|
Invoked by the framework the first time a ThreadLocal variable is used by a thread. Provides a location for subclasses to perform various per/thread initialization.
Reimplemented from ZThread::AbstractThreadLocal. |
|
Inform the framework this value does not propogate to child threads
Reimplemented from ZThread::AbstractThreadLocal. Reimplemented in ZThread::InheritableThreadLocal. |
|
Set a value with this ThreadLocal object. This value can only be retrieved from this ThreadLocal object from the same Thread that set it.
|