Пример #1
0
        public void SmokeTestMultiple(int threadCount, int batchSize, int ringSize)
        {
            var r               = new ConcurrentRing(ringSize);
            var threads         = new Thread[threadCount];
            var actionPerThread = ringSize / threadCount / batchSize;

            for (int i = 0; i < threads.Length; i++)
            {
                threads[i] = new Thread(() =>
                {
                    Span <Submission> submissions = stackalloc Submission[batchSize];
                    for (int j = 0; j < actionPerThread; j++)
                    {
                        Assert.True(r.TryAcquireSubmissions(submissions));
                        for (int k = 0; k < batchSize; k++)
                        {
                            submissions[k].PrepareNop();
                            r.Release(submissions[k]);
                        }
                    }
                });
            }

            foreach (Thread t in threads)
            {
                t.Start();
            }

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

            Assert.Equal(SubmitResult.SubmittedSuccessfully, r.SubmitAndWait((uint)ringSize, out var operationsSubmitted));
            Assert.Equal((uint)ringSize, operationsSubmitted);

            for (int i = 0; i < threads.Length; i++)
            {
                threads[i] = new Thread(() =>
                {
                    for (int j = 0; j < actionPerThread * batchSize; j++)
                    {
                        Assert.True(r.TryRead(out var completion));
                        Assert.Equal(0, completion.Result);
                    }
                });
            }

            foreach (Thread t in threads)
            {
                t.Start();
            }

            foreach (Thread t in threads)
            {
                t.Join();
            }
        }
Пример #2
0
        public void SubmitIntermittedLinkedSubmissions()
        {
            var r = new ConcurrentRing(8);
            Span <Submission> submissions = stackalloc Submission[2];

            Assert.True(r.TryAcquireSubmissions(submissions));

            submissions[0].PrepareNop(options: SubmissionOption.Link);
            r.Release(submissions[0]);

            Assert.Equal(SubmitResult.SubmittedSuccessfully, r.Submit(out var submitted));
            Assert.Equal(1u, submitted);

            Assert.True(r.TryRead(out _));

            submissions[1].PrepareNop(options: SubmissionOption.Link);
            r.Release(submissions[1]);

            Assert.Equal(SubmitResult.SubmittedSuccessfully, r.Submit(out submitted));
            Assert.Equal(1u, submitted);

            Assert.True(r.TryRead(out _));
            Assert.False(r.TryRead(out _));
        }