加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

windows – FLS vs TLS,我可以使用光纤本地存储代替TLS吗?

发布时间:2020-12-14 04:38:26 所属栏目:Windows 来源:网络整理
导读:我的库中有用于win-threads和pthreads的可移植TLS(线程本地存储)代码,但是在WinRT上没有TlsXXX api.但是,there is FlsXXX api that serves almost the same purpose为 the TLS api. 来自MSDN: A fiber can use fiber local storage (FLS) to create a uniqu
我的库中有用于win-threads和pthreads的可移植TLS(线程本地存储)代码,但是在WinRT上没有TlsXXX api.但是,there is FlsXXX api that serves almost the same purpose为 the TLS api.
来自MSDN:

A fiber can use fiber local storage (FLS) to create a unique copy of a variable for each fiber. If no fiber switching occurs,FLS acts exactly the same as thread local storage

那么,这是否意味着我可以简单地使用FlsXXX api作为替代品(我不使用光纤,我不使用__thread说明符用于变量,我直接使用api).

解决方法

First you have to convert the thread to a fiber.

这是你在商店应用程序中无法做到的,不错的鸡蛋问题.这是SDK文档所说的,但实际上并不是Microsoft CRT所做的,它使用FlsAlloc()但从不在任何地方调用ConvertThreadToFiber / Ex().所以你没事,只是从不调用CreateFiber().

是的,如果你不创建光纤according to the SDK,FLS与TLS相同:

A fiber can use fiber local storage (FLS) to create a unique copy of a variable for each fiber. If no fiber switching occurs,FLS acts exactly the same as thread local storage. The FLS functions (FlsAlloc,FlsFree,FlsGetValue,and FlsSetValue) manipulate the FLS associated with the current thread. If the thread is executing a fiber and the fiber is switched,the FLS is also switched.

您还可以看到在CRT中使用,请查看VS2012 vc / crt / src / Platform.cpp源代码文件__TlsAlloc()函数.当_CRT_APP是#defined时,你会看到它回退到FlsAlloc.它适用于VCLibs构建,即Store应用程序中使用的构建.

没有明确记录,但非常有力地证明这很好.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读