当前位置: 首页>>代码示例>>C#>>正文


C# RingBuffer.Publish方法代码示例

本文整理汇总了C#中RingBuffer.Publish方法的典型用法代码示例。如果您正苦于以下问题:C# RingBuffer.Publish方法的具体用法?C# RingBuffer.Publish怎么用?C# RingBuffer.Publish使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在RingBuffer的用法示例。


在下文中一共展示了RingBuffer.Publish方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ValuePublisher

        private static void ValuePublisher(CountdownEvent countdownEvent, RingBuffer<ValueEvent> ringBuffer, long iterations)
        {
            countdownEvent.Signal();
            countdownEvent.Wait();

            for (long i = 0; i < iterations; i++)
            {
                var sequence = ringBuffer.Next();
                var eventData = ringBuffer[sequence];
                eventData.Value = i;
                ringBuffer.Publish(sequence);
            }
        }
开发者ID:disruptor-net,项目名称:Disruptor-net,代码行数:13,代码来源:ThreeToOneSequencedThroughputTest.cs

示例2: ValuePublisher

        private static void ValuePublisher(CountdownEvent countdownEvent, RingBuffer<long[]> ringBuffer, long iterations, long arraySize)
        {
            countdownEvent.Signal();
            countdownEvent.Wait();

            for (long i = 0; i < iterations; i++)
            {
                var sequence = ringBuffer.Next();
                var eventData = ringBuffer[sequence];
                for (var j = 0; j < arraySize; j++)
                {
                    eventData[j] = i + j;
                }
                ringBuffer.Publish(sequence);
            }
        }
开发者ID:disruptor-net,项目名称:Disruptor-net,代码行数:16,代码来源:ThreeToThreeSequencedThroughputTest.cs

示例3: ShouldPreventProducersOvertakingEventProcessorsWrapPoint

        public void ShouldPreventProducersOvertakingEventProcessorsWrapPoint()
        {
            const int ringBufferSize = 4;
            var mre = new ManualResetEvent(false);
            var producerComplete = false;
            var ringBuffer = new RingBuffer<StubEvent>(() => new StubEvent(-1), ringBufferSize);
            var processor = new TestEventProcessor(ringBuffer.NewBarrier());
            ringBuffer.SetGatingSequences(processor.Sequence);

            var thread = new Thread(
                () =>
                    {
                        for (int i = 0; i <= ringBufferSize; i++) // produce 5 events
                        {
                            var sequence = ringBuffer.Next();
                            StubEvent evt = ringBuffer[sequence];
                            evt.Value = i;
                            ringBuffer.Publish(sequence);

                            if (i == 3) // unblock main thread after 4th event published
                            {
                                mre.Set();
                            }
                        }

                        producerComplete = true;
                    });

            thread.Start();

            mre.WaitOne();
            Assert.AreEqual(ringBufferSize - 1, ringBuffer.Cursor);
            Assert.IsFalse(producerComplete);

            processor.Run();
            thread.Join();

            Assert.IsTrue(producerComplete);
        }
开发者ID:Xamarui,项目名称:Disruptor-net,代码行数:39,代码来源:RingBufferTests.cs


注:本文中的RingBuffer.Publish方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。