摘要: // 读取锁可以被多个线程读取 // 写入锁 只能被一个线程写入 一写多读 本质上也是混合锁 private static ReaderWriterLock ssReaderWriterLock =new ReaderWriterLock(); private static ReaderWriter 阅读全文
posted @ 2020-07-31 14:44 谁说程序猿很猥琐 阅读(107) 评论(0) 推荐(0) 编辑
摘要: public static class Sample2 { //互斥锁和自旋锁不同的是 互斥锁获取锁失败后,会等待,而不是重新尝试获取.因为等待所以不会消耗资源。 //线程从等待到唤醒状态到调度运行需要花费一定的时间 // Mutex 互斥锁 private static readonly Mute 阅读全文
posted @ 2020-07-31 14:00 谁说程序猿很猥琐 阅读(225) 评论(0) 推荐(0) 编辑
摘要: private static int a = 0; static void Main(string[] args) { // 原子操作 var b = 0; b = Interlocked.Increment(ref a); // 自增1 b = Interlocked.Decrement(ref 阅读全文
posted @ 2020-07-31 08:02 谁说程序猿很猥琐 阅读(445) 评论(0) 推荐(0) 编辑