惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

N
Netflix TechBlog - Medium
V
Vulnerabilities – Threatpost
Google Online Security Blog
Google Online Security Blog
Hugging Face - Blog
Hugging Face - Blog
L
LINUX DO - 热门话题
云风的 BLOG
云风的 BLOG
P
Proofpoint News Feed
D
Docker
C
Cyber Attacks, Cyber Crime and Cyber Security
MyScale Blog
MyScale Blog
P
Palo Alto Networks Blog
T
Tenable Blog
P
Privacy International News Feed
Google DeepMind News
Google DeepMind News
小众软件
小众软件
Cisco Talos Blog
Cisco Talos Blog
aimingoo的专栏
aimingoo的专栏
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
A
Arctic Wolf
C
Cybersecurity and Infrastructure Security Agency CISA
C
Cisco Blogs
T
Threat Research - Cisco Blogs
NISL@THU
NISL@THU
The Hacker News
The Hacker News
Project Zero
Project Zero
AWS News Blog
AWS News Blog
Simon Willison's Weblog
Simon Willison's Weblog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
T
Threatpost
V
Visual Studio Blog
The GitHub Blog
The GitHub Blog
The Cloudflare Blog
Last Week in AI
Last Week in AI
Jina AI
Jina AI
Cyberwarzone
Cyberwarzone
The Register - Security
The Register - Security
C
CXSECURITY Database RSS Feed - CXSecurity.com
Vercel News
Vercel News
D
Darknet – Hacking Tools, Hacker News & Cyber Security
MongoDB | Blog
MongoDB | Blog
U
Unit 42
Scott Helme
Scott Helme
A
About on SuperTechFans
WordPress大学
WordPress大学
F
Fortinet All Blogs
大猫的无限游戏
大猫的无限游戏
G
GRAHAM CLULEY
Latest news
Latest news
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
S
Schneier on Security

博客园 - John Rambo

定时关机脚本 Mean shift算法处理图像(Scilab & C#) Arimoto–Blahut algorithm (Mathematica) 1分钟搞定QuickSort算法 C#行列式计算程序 MIDL语法详解 (译) Virtual PC2007 + Redhat9下的网络配置 关于IFromatterProvider Total KMP 分析函数调用的汇编指令 why c++/cli About double-checked locking 对透明代理源码的一些理解 ReaderWriterLockSlim CallContext类 GDI+ is F**king unbelievable A better timer 第一个Postsharp插件 WeakReference
System. ThreadStaticAttribute
John Rambo · 2008-11-07 · via 博客园 - John Rambo

今天发现了这个很酷的东西,可以用来标记静态字段。就我的理解,被标记为ThreadStaticAttribute的静态字段的语义将会变化,从一个正常的内存地址变成TLS中的一个存储位置。就当它做访问TLS的一种快捷方式。不同的ThreadStatic静态字段并不会冲突,表示TLS中独立的存储位置。

网上的一篇文章说到了在Asp.net中使用ThreadStatic的一些问题。我不太确定我的理解是否正确,但看起来好象是说,由于asp.net复用托管线程(线程池)来服务请求,因此在对先后发生的多个请求服务时有可能使用的是同一个线程。而TLS不会因为服务新的请求而重置。因此如果ThreadStatic静态字段中保存的信息如果同请求相关,那么后来的请求就会看到前面请求留下来的信息。

有一篇文章还比较了ThreadStatic和CallContext类的静态方法。上面提到CallContext中的数据会传递到从本线程创建的子线程或异步线程中去。(这一点在MSDN中没有提到,所以值得怀疑。但是上面又说HttpContext.Current是通过这个实现的;考虑到HttpContext的行为,感觉人家说的应该是对的。矛盾。)不知道这里说的“传递”是指仅仅把CallContext中的数据复制一份过去还是把CallContext中的数据序列化再反序列化给子线程。我觉得应该是前者。有时间需要测试一下。

妈的现在时间太少了很多东西都只能先靠猜了。

还发现了(instance) HttpContext.Items这个集合。就像其名称所暗示的那样,存储在其中的数据仅仅是用于当前Http请求,这个集合会在每次创建新的HttpContext实例时重新初始化。 

By the way, System命名空间下还有一个ContextStaticAttribute,其中的“Context”是指Remoting中的Context,ContextBoundObject中的Context。是应用程序域下面的结构。