[. NET multithreading] Mutex

Source: Internet
Author: User
Tags mutex

A mutex is a synchronization primitive that can be synchronized between processes.

name description
Mutex()

Initializes a new instance of the Mutex class using the default properties.

mutex (Boolean)

mutex class with a Boolean value that indicates whether the calling thread should has initial Ownership of the mutex. " > Initializes a new instance of the  mutex  class with a Boolean value that indicates whether the calling thread should have initial ownership of the mutex.

mutex (Boolean,? String)

Mutex class with a Boolean value that indicates whether the calling thread should has initial ownership of the mutex, and A string is the name of the mutex.  mutex  class with a Boolean value that indicates whether the calling thread should have initial ownership of the mutex and whether the string is the name of the mutex.

mutex (Boolean,? String,? Boolean)

Mutex class with a Boolean value that indicates whether the calling thread should has initial ownership of the mutex, a s Tring that's the name of the mutex, and a Boolean value, when the method returns, indicates whether the calling Thre Ad was granted initial ownership of the mutex. " You use a Boolean value that indicates whether the calling thread should have initial ownership of the mutex and whether the string is the name of the mutex, and when the thread returns, a Boolean value that indicates whether the calling thread has given initial ownership of the mutex   mutex  class.

Mutex(Boolean,? String,? Boolean,? MutexSecurity)

Initializes a Boolean variable that can indicate whether the calling thread should have initial ownership of the mutex and whether the string is the name of the mutex, and when the thread returns, indicates whether the calling thread has given the mutex initial ownership, and whether access control security has been applied to the named mutex A new instance of the Mutex class.

code Example

When used, the WaitOne function must be paired with the ReleaseMutex function.

Inheritance HierarchySystem. Object
?? System. MarshalByRefObject
???? System.Threading. WaitHandle
?????? system.threading. Mutex the MarshalByRefObject class allows objects to be accessed across application domain boundaries in applications that support remoting.

The mutex is more advanced than the critical section and can be named to support thread synchronization across processes. Mutexes are calls to the Win32 API for mutex operations, so different processes under the same operating system can share locks according to the name of the mutex.

Because of this, the operation of the mutex invokes system resources, and the performance is reduced relative to the critical section. It is better to use critical zone performance for in-process thread synchronization .

Reference Links:

Http://www.myexception.cn/asp-dotnet/2112687.html

http://blog.sina.com.cn/s/blog_68e4d2910100q6uj.htmlhttps://www.cnblogs.com/yinzixin/archive/2011/11/16/2250562.html

[. NET multithreading] Mutex

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.