#include <ThreadLocal.h>
Inheritance diagram for ThreadLocal:
Public Methods | |
virtual | ~ThreadLocal () throw () |
Destroy this ThreadLocal. | |
T | get () const throw () |
T | set (T val) const throw () |
Protected Methods | |
virtual void * | initialValue () const 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 destroyValue() method is invoked when a thread that has used a ThreadLocal is about to exit.
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.
|
Get the value associated with the current thread and this object via fetch(). If no association exists, then initialValue() is invoked.
Reimplemented from AbstractThreadLocal. |
|
Invoked by the framework the first time a get() or set() is invoked on a ThreadLocal variable from a particular thread.
Implements AbstractThreadLocal. |
|
Set the value associated with the current thread and this object. This value can only be retrieved from the current thread.
|