gpt4 book ai didi

c++ - 在非 boost 线程中使用 boost::thread_specific_ptr

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:48:23 26 4
gpt4 key购买 nike

我正在阅读 the documentation section for boost::thread_specific_ptr ,并尝试解析这段:

Note: on some platforms, cleanup of thread-specific data is not performed for threads created with the platform's native API. On those platforms such cleanup is only done for threads that are started with boost::thread unless boost::on_thread_exit() is called manually from that thread.

首先,可能是迂腐的一点:我假设他们的意思是说 boost::this_thread::at_thread_exit() 而不是 boost::on_thread_exit()。否则我真的迷路了。

更重要的是,线程到底需要做什么?将一些空操作函数传递给 at_thread_exit() 就足够了吗,还是需要传递其他东西?

(这个主题在评论 here 中讨论过,但我仍然不确定我需要做什么。)

(背景故事:我正在寻找我提出的问题的解决方案 earlier today)。

最佳答案

经过更多的挖掘,似乎那个神秘的段落确实意味着说 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,就会触发对该函数的调用>.

关于c++ - 在非 boost 线程中使用 boost::thread_specific_ptr,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22448022/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com