コード例 #1
0
ファイル: CacheTests.cs プロジェクト: wgraham17/SharpNoise
        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();
            }
        }
コード例 #2
0
ファイル: CacheTests.cs プロジェクト: rthome/SharpNoise
        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();
        }