ThreadLocalDestructiblePointer Class Reference

#include <threadlocalpointer.h>

Inheritance diagram for ThreadLocalDestructiblePointer:

详细描述

Thread local pointer with notification upon destruction. This is similar to ThreadLocalPointer but when a thread exits or the object is destructed a per-thread notification is invoked which can be used to free resources.

注意
Thread local pointers are a scarce resource. Only a limited number of them can be allocated: On Windows about 100 (there are less FLS than TLS entries) and on OS X about 500. You should only use them if they are the last and only resort to solve a problem. Furthemore for performance reasons it is best to avoid thread local variables at all and instead use some sort of local context (for a group's jobs or with ParallelFor ).
A thread local pointer is bound to a OS thread and the pointer is stored for the lifetime of the thread. If you create and use thread local variables in a module you must ensure that they are destructed properly before the module is unloaded.
On Windows this is 50 % slower than ThreadLocalPointer . Furthermore the code must not use the (deprecated) fiber calls (ConvertThreadToFiber, CreateFiber etc.).

公共成员函数

  ThreadLocalDestructiblePointer ()
  ~ThreadLocalDestructiblePointer ()
Bool   Init (void(*destructionNotification)(void *))
-  Public Member Functions inherited from ThreadLocalPointer
  ThreadLocalPointer ()
  ~ThreadLocalPointer ()
Bool   Init ()
void *  Get () const
Bool   Set (void *value)
Bool   重置 ()
Bool   IsValid () const

私有成员函数

Bool   Init ()

Additional Inherited Members

-  Protected Attributes inherited from ThreadLocalPointer
pthread_key_t  _key

构造函数 & 析构函数文档编制

◆  ThreadLocalDestructiblePointer()

ThreadLocalDestructiblePointer ( )

◆  ~ThreadLocalDestructiblePointer()

~ ThreadLocalDestructiblePointer ( )

成员函数文档编制

◆  Init() [1/2]

Bool Init ( void(*)(void *)  destructionNotification )

Allocates and initializes a thread local pointer.

注意
If you Init() an already initialized thread local pointer, a new one will be created and you cannot access the old one anymore. This behaviour is intended.
The notification will only be invoked if the pointer value is not a nullptr.
参数
[in] destructionNotification To be called when a thread exits or the thread local pointer is destructed.
返回
False if thread local pointer cannot be created.

◆  Init() [2/2]

Bool Init ( )
private