lock为何只能锁定引用不能锁定值类型

他要的就是引用类型,若是你传一个值类型,会装箱,下次代码运行到这里,又会装箱,两次不是同一个对象,因此锁不住this lock(x) {   ... } 实际是经过Monitor对象完成的锁: 上面等同于: System.Object obj = (System.Object)x; System.Threading.Monitor.Enter(obj); try {   ...   } final
相关文章
相关标签/搜索