If you open a C# class, and if the C# class has event delcared, then you might be able to see code as follow.
// Events internal event EventHandler<ModuleInitializeArgs> AfterModuleInitialized { add { EventHandler<ModuleInitializeArgs> handler2; EventHandler<ModuleInitializeArgs> afterModuleInitialized = this.AfterModuleInitialized; do { handler2 = afterModuleInitialized; EventHandler<ModuleInitializeArgs> handler3 = (EventHandler<ModuleInitializeArgs>) Delegate.Combine(handler2, value); afterModuleInitialized = Interlocked.CompareExchange<EventHandler<ModuleInitializeArgs>>(ref this.AfterModuleInitialized, handler3, handler2); } while (afterModuleInitialized != handler2); } remove { EventHandler<ModuleInitializeArgs> handler2; EventHandler<ModuleInitializeArgs> afterModuleInitialized = this.AfterModuleInitialized; do { handler2 = afterModuleInitialized; EventHandler<ModuleInitializeArgs> handler3 = (EventHandler<ModuleInitializeArgs>) Delegate.Remove(handler2, value); afterModuleInitialized = Interlocked.CompareExchange<EventHandler<ModuleInitializeArgs>>(ref this.AfterModuleInitialized, handler3, handler2); } while (afterModuleInitialized != handler2); } }
You may wonder why all the hassle when you you just wantted to comine a handler to an event field.
but let's see why this??
in multple situation, it is common that you lost update, where event are immutable, when you combine a event with a event handler, then a new event will be returned, so before you switch the combined result with the event field, if there is another thread kicks in and stole the update, where it has updated the AfterModuleInitialized event , and then the forestalled thread resume, and it is highly possible the thread will eat up another thread's update. So it will check to see if the this.AfterModuleInitialized is the same as the handler (which store the this.AfterModuleInitialized 's old value), if there is no other thread steals the update, then it is safe to proceed, otherwise, it will do another round until it succes.
相关推荐
The Anatomy of the SIFT method sift的算法文档,分析的非常透彻的资源。
Fundamentals of Anatomy and Physiology for Nursing and Healthcare Students is a succinct but complete overview of the structure and function of the human body, with clinical applications throughout....
In addition, most laboratory manuals on the market contain little more than material repeated from anatomy textbooks, which provides no real benefit to a student. All of these things lead to student ...
解剖深度学习原理,从0实现深度学习库!Anatomy of the Deep Learning Principle,
The Anatomy of a Large-Scale Hypertextual Web Search Engine(论文中英文对照),google创始人写的关于google技术的论文,适合SEO和研究搜索技术的用户
-Radiology With a special emphasis on the complementary nature of anatomic and functional cardiac data, Clinical Cardiac CT: Anatomy and Function -- now in a lavishly illustrated Second Edition -- ...
Blood Supply of the Stomach Complete Anatomy
早寒武世原肠胚内部结构及细胞运动,姚肖永,郑亚娟,梅树村期宽川铺生物群处在寒武纪早期,其中产出的动物卵裂及原肠胚化石为我们研究后生动物的个体发育提供了独一无二的窗口。然而
e-anatomy.apk
A paper on google's pagerank.
The Anatomy of a Large Scale Hypertextual Web Search Engine 中文版 Google的开山之作,不用多说了吧
codeschool backbone 教程 The Anatomy of BackboneJS
Android Anatomy and Physiology
In this paper, we present Google, a prototype of a large-scale search engine which makes heavy use of the structure present in hypertext.
這篇文章中,我們介紹了google,它是一個大型的搜索引擎(of a large-scale search engine)的原 型,搜索引擎在超文本中應用廣泛。Google的設計能夠高效地抓網頁並建立索引,它的查詢結 果比其他現有系統都高明。...
剪切流中靶向脂质体内吞的理论研究,白帆,张恩华,\justifying 本文依据生灭过程理论对剪切流中内皮细胞内吞100nm靶向脂质体的过程进行了建模。为了分析剪切流对内吞的影响,模型中的参数
Yoga Anatomy’s Keys - The Functional Guide for Beginners
In this book, we are going to give you an overview of the concepts that you have to understand before you actually start programming in the C language. We will explain to you the different elements ...
Describes and illustrates the important aspects of anatomy, physiology, and pathophysiology.Clearly organized and written, this guide is ideal for students with a limited background in science. The ...