The. NET framework's CLR provides three ways to complete the methods and domains for shared resources, such as global variable fields, specific code snippets, static and instantiated.
(1) Code domain synchronization: Use the Monitor class to synchronize the entire code of a static/instantiated method or part of a code snippet. Synchronization of static domains is not supported. In the instantiated method, the this pointer is used for synchronization, and in the static method, the class is used for synchronization, which is discussed later.
(2) Manual synchronization: Use different synchronization classes (such as WaitHandle, mutexes, ReaderWriterLock, ManualResetEvent, AutoResetEvent, and interlocked, etc.) to create your own synchronization mechanism. This synchronization requires you to manually synchronize the different domains and methods, which can also be used for inter-process synchronization and deadlock cancellation caused by waiting on shared resources.
(3) Context synchronization: Use SynchronizationAttribute to create simple, automatic synchronization for ContextBoundObject objects. This synchronization method is only used for the synchronization of the instantiated methods and domains. All objects in the same context domain share the same lock.
;
Welcome reprint, but please keep the source, this article to [China Soft net] original link: http://www.huarw.com/program/net/c/200609/38094.html
The. NET framework CLR provides three ways to complete a shared resource