...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
|
Boost.ThreadsHeader <boost/thread/tss.hpp> |
thread_specific_ptr
thread_specific_ptr
synopsisthread_specific_ptr
constructors and destructorthread_specific_ptr
modifier functionsthread_specific_ptr
observer functionsThe header <boost/thread/tss.hpp> defines the class thread_specific_ptr which is used to manage data associated with specific thread instances.
thread_specific_ptr
The thread_specific_ptr
class defines an interface for using thread
specific storage. Thread specific storage is data associated with individual
threads and is often used to make operations thread-safe
that rely on global data.
Template thread_specific_ptr
stores a pointer to an object obtained
via new
on a thread-by-thread basis and calls delete on the contained
pointer when the thread terminates. Each thread initially stores the null pointer
in each thread_specific_ptr
instance.
The template thread_specific_ptr
is useful in the following cases:
thread_specific_ptr
synopsisnamespace boost { template <typename T> class thread_specific_ptr : private boost::noncopyable // Exposition only. // Class thread_specific_ptr meets the NonCopyable requirement. { public: thread_specific_ptr(); ~thread_specific_ptr(); T* get() const; T* operator->() const; T& operator*() const; T* release(); void reset(T* p=0); }; };
thread_specific_ptr
constructors and destructorthread_specific_ptr();
delete get()
is well formed.*this
in all threads, with each thread initially storing a
null pointer.boost::thread_resource_error
if the necessary
resources can not be obtained.~thread_specific_ptr();
thread_specific_ptr
object until you are certain there are no threads running that have made use
of its thread specific storage.thread_specific_ptr
modifier functionsT* release();
*this
holds the null pointer for the
current thread.this->get()
prior to the call.void reset(T* p=0);
this->get()!= p
then delete this->get()
.
*this
holds the pointer p
for the current thread.thread_specific_ptr
observer functionsT* get() const;
*this
.T* operator->() const;
this-<get()
.T& operator*() const;
this-<get() != 0
this-<get()
.Revised 05 November, 2001
© Copyright William E. Kempf 2001-2002. All Rights Reserved.
Permission to use, copy, modify, distribute and sell this software and its documentation for any purpose is hereby granted without fee, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation. William E. Kempf makes no representations about the suitability of this software for any purpose. It is provided "as is" without express or implied warranty.