如何保护关键区域 [英] how to protect the critical region
本文介绍了如何保护关键区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何用C#编程语言处理关键区域.有这种情况的例子吗?
或参考资料解释
How to deal with the critical region in the programming language C #. Is there an example of this case
Or reference explaining that
推荐答案
您的意思是类似于关键部分,是为了使您代码安全吗?
然后,c#中的lock关键字将对您有所帮助.
Do you mean anything like a critical section, to make you''re code threadsafe?
Then the lock keyword in c# will help you.
public ThreadSafeClass
{
object criticalSection = new object();
public void SomeMethod()
{
lock(critialSection)
{
// you're synchronization critical stuff goes here..
}
}
}
这篇关于如何保护关键区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文