在C 11
Thread-Local Variables: A Deeper Dive
When a thread is created, a separate copy of the thread-local variables is assigned to it. These variables can be accessed by all threads, but any modifications made to a particular thread-local variable are only visible to the thread that created it.
Thread-local variables add a new storage duration category to the existing ones:
Automatic (exists within a function or block)Static (exists for the lifetime of the program)Dynamic (allocated on the heap)多个多个局部较高范围:共享的全局变量过早隔离线程特定的错误和异常处理,thread_local提供了一种创建变量的机制,可以通过特定的线程安全性和隔离线程安全性和隔离线程依赖性数据来访问且可修改的变量。
免责声明: 提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发到邮箱:[email protected] 我们会第一时间内为您处理。
Copyright© 2022 湘ICP备2022001581号-3