线程特定指针如何工作
How do thread specific pointers work
最近我发现了 boost 线程特定指针的魔力。在对线程安全进行一些研究之后,我想知道如何精确地提升线程特定指针 work.However,我似乎无法在文档中找到它。任何人都可以提供一些关于这个或一些详细文档的见解吗?
来自提升 docs on thread local storage:
boost::thread_specific_ptr
provides a portable mechanism for thread-local storage that works on all compilers supported by Boost.Thread. Each instance of boost::thread_specific_ptr
represents a pointer to an object (such as errno
) where each thread must have a distinct value. The value for the current thread can be obtained using the get()
member function, or by using the * and -> pointer deference operators. Initially the pointer has a value of NULL in each thread, but the value for the current thread can be set using the reset()
member function.
你可以找到 Boost source here。
最近我发现了 boost 线程特定指针的魔力。在对线程安全进行一些研究之后,我想知道如何精确地提升线程特定指针 work.However,我似乎无法在文档中找到它。任何人都可以提供一些关于这个或一些详细文档的见解吗?
来自提升 docs on thread local storage:
boost::thread_specific_ptr
provides a portable mechanism for thread-local storage that works on all compilers supported by Boost.Thread. Each instance ofboost::thread_specific_ptr
represents a pointer to an object (such aserrno
) where each thread must have a distinct value. The value for the current thread can be obtained using theget()
member function, or by using the * and -> pointer deference operators. Initially the pointer has a value of NULL in each thread, but the value for the current thread can be set using thereset()
member function.
你可以找到 Boost source here。