[.net multithreading]Mutex

Mutex is a synchronization primitive that can synchronize between processes.

  name illustrate
System_CAPS_pubmethod Mutex()

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

System_CAPS_pubmethod Mutex(Boolean)

Initializes  a new instance of the Mutex class with a Boolean value indicating whether the calling thread should have initial ownership of the mutex.

System_CAPS_pubmethod Mutex(Boolean, String)

Initializes a new instance of the Mutex class with a Boolean value indicating whether the calling thread should have initial ownership of the mutex and whether the string is the name of the mutex  .

System_CAPS_pubmethod Mutex(Boolean, String, Boolean)

Initializes the Mutex 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, and a Boolean value that indicates whether the calling thread has given initial ownership of the mutex when the thread  returns A new instance of the class.

System_CAPS_pubmethod Mutex(Boolean, String, Boolean, MutexSecurity)

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 to indicate whether the calling thread has given initial ownership of the mutex and whether access control is safe A Boolean variable that has been applied to the named mutex initializes  a new instance of the Mutex class.

code example

When used, the WaitOne function and the ReleaseMutex function must be used in pairs.

System.Object
  System.MarshalByRefObject
    System.Threading.WaitHandle
      System.Threading.Mutex
The MarshalByRefObject class  allows objects to be accessed across application domain boundaries in remoting-enabled applications.
 

Mutexes are more advanced than critical sections. Mutexes can be named to support thread synchronization across processes. Mutex is the operation of the called Win32 API on the mutex, so different processes under the same operating system can share the lock according to the name of the mutex.

Because of this, the operation of the mutex will call system resources, and the performance is also reduced relative to the critical section. Using critical sections for thread synchronization within a process will perform better .

 

Reference link:

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

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325378584&siteId=291194637