Exemplo n.º 1
0
        protected override double RunDisruptorPass(int passNumber)
        {
            stepThreeFunctionHandler.reset();

            Task.Factory.StartNew(stepOneBatchConsumer.Run);
            Task.Factory.StartNew(stepTwoBatchConsumer.Run);
            Task.Factory.StartNew(stepThreeBatchConsumer.Run);

            var stopwatch = new Stopwatch();

            stopwatch.Start();

            long operandTwo = OPERAND_TWO_INITIAL_VALUE;

            for (long i = 0; i < ITERATIONS; i++)
            {
                FunctionEntry entry = producerBarrier.NextEntry();
                entry.OperandOne = i;
                entry.OperandTwo = operandTwo--;
                producerBarrier.Commit(entry);
            }

            long expectedSequence = ringBuffer.Cursor;

            while (stepThreeBatchConsumer.Sequence < expectedSequence)
            {
                // busy spin
            }

            stopwatch.Stop();
            double opsPerSecond = ITERATIONS / stopwatch.Elapsed.TotalSeconds;

            stepOneBatchConsumer.Halt();
            stepTwoBatchConsumer.Halt();
            stepThreeBatchConsumer.Halt();

            Assert.AreEqual(expectedResult, stepThreeFunctionHandler.getStepThreeCounter());

            return(opsPerSecond);
        }