1、volatile关键字
public class A
{
private volatile int _i;
public int I
{
get { return _i; }
set { _i = value; }
}
}
2、lock关键字
public void Function()
{
object lockThis = new object ();
lock (lockThis)
{
// Access thread-sensitive resources.
}
}
3、System.Threading.Interlocked
4、同步事件和等待句柄 |