gpt4 book ai didi

c++ - 线程特定指针如何工作

转载 作者:行者123 更新时间:2023-11-28 02:21:52 24 4
gpt4 key购买 nike

最近我发现了 boost 线程特定指针的魔力。在对线程安全进行了一些研究之后,我想知道 boost 线程特定指针究竟是如何工作的。但是,我似乎无法在文档中找到它。任何人都可以提供一些关于这个或一些详细文档的见解吗?

最佳答案

来自 Boost docs on thread local storage :

boost::thread_specific_ptr provides a portable mechanism for thread-local storage that works on all compilers supported by Boost.Thread. Each instance of boost::thread_specific_ptr represents a pointer to an object (such as errno) where each thread must have a distinct value. The value for the current thread can be obtained using the get() member function, or by using the * and -> pointer deference operators. Initially the pointer has a value of NULL in each thread, but the value for the current thread can be set using the reset() member function.

你可以找到 Boost source here .

关于c++ - 线程特定指针如何工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32124645/

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