我正在阅读文档部分boost::thread_specific_ptr http://www.boost.org/doc/libs/1_55_0/doc/html/thread/thread_local_storage.html,并尝试解析这一段:
注意:在某些平台上,不会对使用平台的本机 API 创建的线程执行线程特定数据的清理。在这些平台上,此类清理仅针对以 boost::thread 启动的线程进行,除非从该线程手动调用 boost::on_thread_exit() 。
首先,可能是一个迂腐的观点:我认为他们的意思是boost::this_thread::at_thread_exit()
而不是boost::on_thread_exit()
。不然我就真的迷路了。
更重要的是,线程到底需要做什么?将一些无操作函数传递给 at_thread_exit() 是否足够,或者是否需要传递其他内容?
(这个话题在评论里讨论过here https://stackoverflow.com/a/4788440/3117832,但我仍然不确定我需要做什么。)
(背景故事:我正在寻找我提出的问题的解决方案今天早些时候 https://stackoverflow.com/questions/22446534/dynamic-tls-in-c11).
经过进一步挖掘,似乎这段神秘的段落确实意味着on_thread_exit()
。它指的是一个未记录的函数,它不带任何参数。
以下是该函数的声明和随附的注释,来自 boost_1_55_0/boost/thread/detail/tss_hooks.hpp:
BOOST_THREAD_DECL void __cdecl on_thread_exit(void);
//Function to be called just be fore a thread ends
//in an exe or dll that uses Boost.Threads.
//Must be called in the context of the thread
//that is ending.
//Called automatically by Boost.Threads when
//a method for doing so has been discovered.
//Must not be omitted; may be called multiple times.
所以,iiuc,我需要做的是编写特定于平台的代码,每当任何类型的线程终止时(如果该线程一直在使用),都会触发对此函数的调用boost::thread_specific_ptr
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)