Beispiel #1
0
        public void Dispose_ReturnsAllBuffers(bool amountBufferOnly, int threadCount)
        {
            var buffers = new ThreadLocalBlenderBuffers <Rgb24>(this.memoryAllocator, 100, amountBufferOnly);

            void RunThread()
            {
                buffers.AmountSpan[0] = 42;
            }

            Thread[] threads = new Thread[threadCount];
            for (int i = 0; i < threadCount; i++)
            {
                threads[i] = new Thread(RunThread);
                threads[i].Start();
            }

            foreach (Thread thread in threads)
            {
                thread.Join();
            }

            buffers.Dispose();

            int expectedReturnCount = amountBufferOnly ? threadCount : 2 * threadCount;

            Assert.Equal(expectedReturnCount, this.memoryAllocator.ReturnLog.Count);
        }