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

推荐订阅源

Know Your Adversary
Know Your Adversary
云风的 BLOG
云风的 BLOG
Recent Announcements
Recent Announcements
F
Fortinet All Blogs
B
Blog
罗磊的独立博客
宝玉的分享
宝玉的分享
Vercel News
Vercel News
Martin Fowler
Martin Fowler
N
Netflix TechBlog - Medium
P
Proofpoint News Feed
T
Threatpost
Security Latest
Security Latest
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Stack Overflow Blog
Stack Overflow Blog
I
Intezer
P
Privacy International News Feed
D
Docker
月光博客
月光博客
博客园 - 三生石上(FineUI控件)
M
MIT News - Artificial intelligence
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
L
Lohrmann on Cybersecurity
Google DeepMind News
Google DeepMind News
The Last Watchdog
The Last Watchdog
A
Arctic Wolf
IT之家
IT之家
S
SegmentFault 最新的问题
S
Securelist
博客园 - 叶小钗
N
News and Events Feed by Topic
F
Full Disclosure
Security Archives - TechRepublic
Security Archives - TechRepublic
Engineering at Meta
Engineering at Meta
Hacker News: Ask HN
Hacker News: Ask HN
博客园 - Franky
GbyAI
GbyAI
AI
AI
Y
Y Combinator Blog
WordPress大学
WordPress大学
Latest news
Latest news
Microsoft Security Blog
Microsoft Security Blog
人人都是产品经理
人人都是产品经理
N
News | PayPal Newsroom
The Cloudflare Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
I
InfoQ

博客园 - 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。是应用程序域下面的结构。