Boost线程特定存储问题(boost / thread / tss.hpp) [英] Boost Thread Specific Storage Question (boost/thread/tss.hpp)

查看:334
本文介绍了Boost线程特定存储问题(boost / thread / tss.hpp)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

boost线程库具有针对线程特定的抽象(本地)存储。我已经撇过源代码,似乎TSS功能可以在任何现有线程的应用程序中使用,而不管天气是从boost :: thread --ie创建的,这意味着某些回调注册到内核到钩子在回调函数中,当线程或进程超出范围时,可以调用任何TSS对象的析构函数。我找到了这些回调。

The boost threading library has an abstraction for thread specific (local) storage. I have skimmed over the source code and it seems that the TSS functionality can be used in an application with any existing thread regardless of weather it was created from boost::thread --i.e., this implies that certain callbacks are registered with the kernel to hook in a callback function that may call the destructor of any TSS objects when the thread or process is going out of scope. I have found these callbacks.

我需要从各种网络服务器的工作线程中缓存来自OpenSSL的HMAC_CTX(参见,详细的,我想要做的问题),因此我不控制线程的生命周期 - web-服务器。因此,我将在不是由boost :: thread创建的线程上使用TSS功能。

I need to cache HMAC_CTX's from OpenSSL inside the worker threads of various web-servers (see this, detailed, question for what I am trying to do), and as such I do not controll the life-time of the thread -- the web-server does. Therefore I will use the TSS functionality on threads not created by boost::thread.

我只想在开始实现缓存逻辑之前验证我的假设,我的逻辑缺陷?

I just wanted to validate my assumptions before I started implementing the caching logic, are there any flaws in my logic ?

推荐答案

你说得对。你可以使用它不是由boost :: thread创建的线程。
如果你看看test_tss.cpp,你可以看到他们测试完全是这样,它应该与POSIX和Windows线程。

You're right. You can use it for threads not created by boost::thread. If you look in test_tss.cpp you can see they test exactly that, and it should work with both POSIX and Windows threads.

这篇关于Boost线程特定存储问题(boost / thread / tss.hpp)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆