C# – 二十八线程 之 锁系统

lock

关键字,

 

Monitor

监控器,

using System.Threading;
// 提供同步访问对象的机制。
public static class Monitor {
    public static bool Wait(object obj, xxx);
    public static void Enter(object obj, xxx);
    public static bool TryEnter(object obj, xxx);
    public static void Exit(object obj);
    public static void Pulse(object obj);
    public static void PulseAll(object obj);
} 

 

参考:

  •  ;

Semaphore

信号量,

using System.Threading;
// 限制可同时访问某一资源或资源池的线程数
public sealed class Semaphore : WaitHandle {
    public Semaphore(int initialCount, int maximumCount, xxx);
    public static Semaphore OpenExisting(string name, xxx);
    public int Release();
    public int Release(int releaseCount);
}

  

Mutex

互斥体,

using System.Threading;
// 一个同步基元,也可用于进程间同步。
public sealed class Mutex : WaitHandle {
    public Mutex();
    public Mutex(bool initiallyOwned, xxx);
    public static Mutex OpenExisting(string name);
    public void ReleaseMutex();
}

  

参考:

 

相关文章