摘要:
lock:该关键字将语句块标记为临界区,方法是获取给定对象的互斥锁,执行语句,然后释放该锁。举例: 单件模式publicclassSingleton{privatestaticSingletoninstance=null;privatestaticreadonlyobjectsyncRoot=newobject();privateSingleton(){}publicstaticSingletonGetInstance(){if(instance==null){lock(syncRoot){if(instance==null){instance=newSingleton();}}}return 阅读全文