代码改变世界

随笔档案-2012年09月

.NET中简易实现线程安全

2012-09-10 19:32 by uonun, 507 阅读, 收藏,
摘要: 在.NET中要实现线程安全,可有多种途径:1. 使用 lock 关键字:1usingSystem;2usingSystem.Threading;34namespaceUDNZ.SynTest5{6classProgram7{8staticint_x=0;9staticint_n=1000000;10staticobject_lock=newobject();1112staticvoidMain(string[]args)13{14EventWaitHandlew1=newEventWaitHandle(false,EventResetMode.AutoReset);15EventWaitHan 阅读全文