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.
相关推荐
SIFT(Scale-Invariant Feature Transform,尺度不变特征变换)是一种流行的图像匹配算法,由David Lowe在1999年提出,并在2004年的文章中进一步完善。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 ...
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
早寒武世原肠胚的内部结构及细胞运动的研究为我们提供了后生动物个体发育的独特窗口。文章主要探讨了从早寒武世地层中发现的胚胎化石,这些化石不仅展示了从卵裂阶段到原肠胚阶段的发育过程,还提供了这一时期发育...
文章《The Anatomy of a Large-Scale Hypertextual Web Search Engine》(以下简称《Anatomy》)深入介绍了Google搜索引擎的设计理念和技术细节,这是一款能够高效抓取网页并建立索引的大型搜索引擎。 #### 二、...
Anatomy of the Deep Learning Principle"的压缩包文件,可能包含了一系列关于深度学习基础知识和实现深度学习库的教程或代码示例。 首先,深度学习的基础原理包括以下几个核心概念: 1. **神经网络**:深度学习的...
1998年,谷歌创始人Sergey Brin和Lawrence Page发表了《The_Anatomy_of_a_Large-Scale_Hypertextual_Web_Search_Engine》一文,详细介绍了Google搜索引擎的设计理念与核心技术。这篇文章不仅对搜索引擎领域产生了...
本文的标题和描述指的是对剪切流环境下,100纳米尺度的靶向脂质体被内皮细胞内吞过程的理论研究。文章基于生灭过程理论,构建了相关的数学模型,重点分析了剪切流参数对靶向脂质体在内皮细胞中的内吞作用的影响,该...
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 ...
《大规模超文本网络搜索引擎的解剖》 这篇论文由Sergey Brin和Lawrence Page撰写,两位作者来自斯坦福大学计算机科学系。他们的研究工作主要集中在如何利用超文本中的结构来构建一个大规模的搜索引擎——Google。...
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 ...
游戏引擎剖析 (Game Engine Anatomy)英文版
《Android Anatomy and Physiology》是关于Android操作系统深度解析的资料,主要涵盖了Android系统的核心结构与运行机制。这篇文档可能源自2008年Google I/O大会的演讲,那时Android系统初露头角,开发者们对它的...