public void TestMultithreaded(int threadCount) { var source = new ThreadIdModule(); var cache = new Cache { Source0 = source }; var threadArray = new Thread[threadCount]; bool startFlag = false; for (int i = 0; i < threadArray.Length; i++) { threadArray[i] = new Thread(() => { for (int k = 0; k < 500; k++) { SpinWait.SpinUntil(() => startFlag); var sourceValue = source.GetValue(0, 0, 0); Assert.Equal(sourceValue, cache.GetValue(0, 0, 0)); Assert.Equal(sourceValue, cache.GetValue(0, 0, 0)); } }); } for (int i = 0; i < threadArray.Length; i++) { threadArray[i].Start(); } startFlag = true; for (int i = 0; i < threadArray.Length; i++) { threadArray[i].Join(); } }
public void TestMultithreaded(int threadCount) { var source = new ThreadIdModule(); var cache = new Cache { Source0 = source }; var threadArray = new Thread[threadCount]; bool startFlag = false; for (int i = 0; i < threadArray.Length; i++) { threadArray[i] = new Thread(() => { for (int k = 0; k < 500; k++) { SpinWait.SpinUntil(() => startFlag); var sourceValue = source.GetValue(0, 0, 0); Assert.Equal(sourceValue, cache.GetValue(0, 0, 0)); Assert.Equal(sourceValue, cache.GetValue(0, 0, 0)); } }); } for (int i = 0; i < threadArray.Length; i++) threadArray[i].Start(); startFlag = true; for (int i = 0; i < threadArray.Length; i++) threadArray[i].Join(); }