Boost Thread Specific Storage Question (boost/thread/tss.hpp)

一世执手 提交于 2019-12-10 22:02:13

问题


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.

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 ?


回答1:


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.




回答2:


This is partially right, as the destructor is not called when the main thread finish.



来源:https://stackoverflow.com/questions/2623396/boost-thread-specific-storage-question-boost-thread-tss-hpp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!