TLS thread local storing
来源:互联网 发布:税务数据共享 编辑:程序博客网 时间:2024/05/16 10:10
template<typename T> class ThreadLocal { public: ThreadLocal() { pthread_key_create(&_pkey, &ThreadLocal::destructor); (void)sizeof(T); } ~ThreadLocal() { pthread_key_delete(_pkey); } T& value() { T* thread_value = static_cast<T*>(pthread_getspecific(_pkey)); if (thread_value == NULL) { T* new_obj = new T(); pthread_setspecific(_pkey, new_obj); thread_value = new_obj; } return *thread_value; } template <typename A1> T& value(A1 arg1) { T* thread_value = static_cast<T*>(pthread_getspecific(_pkey)); if (!thread_value) { T* new_obj = new T(arg1); pthread_setspecific(_pkey, new_obj); thread_value = new_obj; } return *thread_value; } ThreadLocal& operator=(const T& v) { value() = v; return *this; } operator T() const { T* thread_value = static_cast<T*>(pthread_getspecific(_pkey)); return *thread_value; } private: static void destructor(void *x) { T* obj = static_cast<T*>(x); delete obj; } private: pthread_key_t _pkey; };
0 0
- TLS thread local storing
- TLS (Thread local storage)
- Thread-Local Storage(TLS)
- TLS:Thread Local Storage
- TLS:Thread Local Storage
- Thread-Local Storage: TLS
- Thread Local Storage(TLS)
- Thread Local Storage (TLS)
- TLS(Thread Local Storage)入门
- 线程本地存储(Thread Local Storage, TLS)
- 为什么需要TLS(Thread Local Storage)?
- pthread的TLS(THREAD LOCAL STORAGE)
- 线程局部存储TLS(thread local storage)
- 线程本地存储(Thread Local Storage, TLS)分析与使用
- 线程局部存储Thread Local Storage(TLS)
- 线程本地存储(Thread Local Storage TLS)
- TLS(thread - local storage)线程局部存储
- 线程局部存储(Thread Local Storage,TLS)
- 反射机制
- bash的通配符
- WAS的VGC参数
- CentOS下载百度网盘文件的方法
- C#中的自定义控件
- TLS thread local storing
- 情景再现,从源码角度分析异常:The specified child already has a parent
- Hibernate初学抽取工具类错误
- zip(*I)与zip(I)区别
- 欢迎使用CSDN-markdown编辑器
- 【解决】由于没有远程桌面授权服务器可以提供许可证,远程回话被中断
- Windows下Git多账号配置,同一电脑多个ssh-key的管理
- mylib使用说明
- kewastUnPackStats(): bad magic 1