The. NET framework CLR provides three ways to complete a shared resource

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.