标签:line reads ola vat OLE ons 通信 col 读取
当线程通过共享内存互相通信时,调用Volatile.Write来写入最后一个值,调用Volatile.Read来读取第一个值
public class ThreadsSharingData { private volatile int flag = 0; private int value = 0; public void Thread1() { //注意在将1写入flag之前,必须先将5写入value value = 5; flag = 1; } public void Thread2() { //注意在value必须在读取了flag之后才能读取 if (flag == 1) Console.WriteLine(value); } }
标签:line reads ola vat OLE ons 通信 col 读取
原文地址:https://www.cnblogs.com/kikyoqiang/p/10211988.html