• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# AtomicBoolean类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中AtomicBoolean的典型用法代码示例。如果您正苦于以下问题:C# AtomicBoolean类的具体用法?C# AtomicBoolean怎么用?C# AtomicBoolean使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



AtomicBoolean类属于命名空间,在下文中一共展示了AtomicBoolean类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: FromValue

 public static AtomicBoolean FromValue (bool value)
 {
         AtomicBoolean temp = new AtomicBoolean ();
         temp.Value = value;
         
         return temp;
 }
开发者ID:ddfczm,项目名称:Project-Dollhouse,代码行数:7,代码来源:AtomicBoolean.cs


示例2: SingleThreadExecutor

        /// <summary>
        /// Creates a new <c>SingleThreadExecutor</c> using a custom thread priority.
        /// </summary>
        /// <param name="priority">
        /// The priority to assign the thread.
        /// </param>
        public SingleThreadExecutor(ThreadPriority priority) {
            _actions = new BlockingQueue<Action>();
            _running = new AtomicBoolean(false);
            _shuttingDown = new AtomicBoolean(false);

            _priority = priority;
        }
开发者ID:mbolt35,项目名称:CSharp.Atomic,代码行数:13,代码来源:SingleThreadExecutor.cs


示例3: WidgetBuilderThread

 public WidgetBuilderThread(WidgetBuilder widgetBuilder, string text, ParentWidget parent, AtomicBoolean failFlag)
 {
     this.widgetBuilder = widgetBuilder;
     this.text = text;
     this.parent = parent;
     this.failFlag = failFlag;
 }
开发者ID:mikemajesty,项目名称:Livro-CleanCode,代码行数:7,代码来源:WidgetBuilderThread.cs


示例4: AtomicBoolean_Load_Should_Success

 public void AtomicBoolean_Load_Should_Success()
 {
     var atomicBoolean = new AtomicBoolean(true);
     Assert.Equal(true, atomicBoolean.Load(MemoryOrder.Relaxed));
     Assert.Equal(true, atomicBoolean.Load(MemoryOrder.Acquire));
     Assert.Equal(true, atomicBoolean.Load(MemoryOrder.AcqRel));
     Assert.Equal(true, atomicBoolean.Load(MemoryOrder.SeqCst));
 }
开发者ID:wheercool,项目名称:atomics.net,代码行数:8,代码来源:AtomicBooleanLoadStoreTests.cs


示例5: IndexerThread

 public IndexerThread(IndexWriter w, FacetsConfig config, TaxonomyWriter tw, ReferenceManager<SearcherAndTaxonomy> mgr, int ordLimit, AtomicBoolean stop)
 {
     this.w = w;
     this.config = config;
     this.tw = tw;
     this.mgr = mgr;
     this.ordLimit = ordLimit;
     this.stop = stop;
 }
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:9,代码来源:TestSearcherTaxonomyManager.cs


示例6: ToBoolean

        /// <summary>
        /// Extracts a <see cref="Boolean"/> from an instance of <see cref="AtomicBoolean"/>.
        /// </summary>
        /// <param name="atomicBoolean">The <see cref="AtomicBoolean"/> to extract the value of.</param>
        /// <exception cref="ArgumentNullException">
        /// Thrown if <paramref name="atomicBoolean" /> is <see langword="null"/>.
        /// </exception>
        /// <returns>the value of the <see cref="AtomicBoolean"/>.</returns>
        public static bool ToBoolean(AtomicBoolean atomicBoolean)
        {
            if (atomicBoolean == null)
            {
                throw new InvalidCastException();
            }

            return atomicBoolean.Value;
        }
开发者ID:shoftee,项目名称:OpenStory,代码行数:17,代码来源:AtomicBoolean.cs


示例7: Execute

        public Result<bool> Execute(IAggregateRootId aggregateRootId, int aggregateRootRevision, Action action)
        {
            var result = new Result<bool>(false);
            var acquired = new AtomicBoolean(false);

            try
            {
                if (aggregateLock.TryGetValue(aggregateRootId, out acquired) == false)
                {
                    acquired = acquired ?? new AtomicBoolean(false);
                    if (aggregateLock.TryAdd(aggregateRootId, acquired) == false)
                        aggregateLock.TryGetValue(aggregateRootId, out acquired);
                }

                if (acquired.CompareAndSet(false, true))
                {
                    try
                    {
                        AtomicInteger revision = null;
                        if (aggregateRevisions.TryGetValue(aggregateRootId, out revision) == false)
                        {
                            revision = new AtomicInteger(aggregateRootRevision - 1);
                            if (aggregateRevisions.TryAdd(aggregateRootId, revision) == false)
                                return result;
                        }
                        var currentRevision = revision.Value;
                        if (revision.CompareAndSet(aggregateRootRevision - 1, aggregateRootRevision))
                        {
                            try
                            {
                                action();
                                return Result.Success;
                            }
                            catch (Exception)
                            {
                                revision.GetAndSet(currentRevision);
                                throw;
                            }
                        }
                    }
                    finally
                    {
                        acquired.GetAndSet(false);
                    }
                }

                return result;
            }
            catch (Exception ex)
            {
                return result.WithError(ex);
            }
        }
开发者ID:fetishism,项目名称:Cronus,代码行数:53,代码来源:InMemoryAggregateRootAtomicAction.cs


示例8: CompareExpectedValueAndSetNewValue

 public void CompareExpectedValueAndSetNewValue()
 {
     AtomicBoolean ai = new AtomicBoolean( true );
     Assert.AreEqual( true, ai.Value );
     Assert.IsTrue( ai.CompareAndSet( true, false ) );
     Assert.AreEqual( false, ai.Value );
     Assert.IsTrue( ai.CompareAndSet( false, false ) );
     Assert.AreEqual( false, ai.Value );
     Assert.IsFalse( ai.CompareAndSet( true, false ) );
     Assert.IsFalse( ( ai.Value ) );
     Assert.IsTrue( ai.CompareAndSet( false, true ) );
     Assert.AreEqual( true, ai.Value );
 }
开发者ID:rlxrlxrlx,项目名称:spring-net-threading,代码行数:13,代码来源:AtomicBooleanTests.cs


示例9: CompareExpectedValueAndSetNewValueInMultipleThreads

        public void CompareExpectedValueAndSetNewValueInMultipleThreads()
        {
            AtomicBoolean ai = new AtomicBoolean( true );
            var t = ThreadManager.StartAndAssertRegistered("T1",delegate
                    {
                        while (!ai.CompareAndSet(false, true))
                            Thread.Sleep(Delays.Short);
                    }
                );

            Assert.IsTrue( ai.CompareAndSet( true, false ), "Value" );
            ThreadManager.JoinAndVerify();
            Assert.IsFalse( t.IsAlive, "Thread is still alive." );
            Assert.IsTrue( ai.Value );
        }
开发者ID:rlxrlxrlx,项目名称:spring-net-threading,代码行数:15,代码来源:AtomicBooleanTests.cs


示例10: TestBlockingReceiveWithTimeout

 public void TestBlockingReceiveWithTimeout()
 {
     QueueChannel channel = new QueueChannel();
     AtomicBoolean receiveInterrupted = new AtomicBoolean(false);
     CountDownLatch latch = new CountDownLatch(1);
     Thread t = new Thread(new ThreadStart(delegate
                                               {
                                                   IMessage message = channel.Receive(new TimeSpan(10000));
                                                   receiveInterrupted.Value = true;
                                                   Assert.IsTrue(message == null);
                                                   latch.CountDown();
                                               }));
     t.Start();
     //Assert.IsFalse(receiveInterrupted.Value);
     t.Interrupt();
     latch.Await();
     Assert.IsTrue(receiveInterrupted.Value);
 }
开发者ID:rlxrlxrlx,项目名称:spring-net-integration,代码行数:18,代码来源:QueueChannelTests.cs


示例11: TestApplyDeletesOnFlush

 public virtual void TestApplyDeletesOnFlush()
 {
     Directory dir = NewDirectory();
     // Cannot use RandomIndexWriter because we don't want to
     // ever call commit() for this test:
     AtomicInteger docsInSegment = new AtomicInteger();
     AtomicBoolean closing = new AtomicBoolean();
     AtomicBoolean sawAfterFlush = new AtomicBoolean();
     IndexWriter w = new IndexWriterAnonymousInnerClassHelper(this, dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random())).SetRAMBufferSizeMB(0.5).SetMaxBufferedDocs(-1).SetMergePolicy(NoMergePolicy.NO_COMPOUND_FILES).SetReaderPooling(false), docsInSegment, closing, sawAfterFlush);
     int id = 0;
     while (true)
     {
         StringBuilder sb = new StringBuilder();
         for (int termIDX = 0; termIDX < 100; termIDX++)
         {
             sb.Append(' ').Append(TestUtil.RandomRealisticUnicodeString(Random()));
         }
         if (id == 500)
         {
             w.DeleteDocuments(new Term("id", "0"));
         }
         Document doc = new Document();
         doc.Add(NewStringField("id", "" + id, Field.Store.NO));
         doc.Add(NewTextField("body", sb.ToString(), Field.Store.NO));
         w.UpdateDocument(new Term("id", "" + id), doc);
         docsInSegment.IncrementAndGet();
         // TODO: fix this test
         if (SlowFileExists(dir, "_0_1.del") || SlowFileExists(dir, "_0_1.liv"))
         {
             if (VERBOSE)
             {
                 Console.WriteLine("TEST: deletes created @ id=" + id);
             }
             break;
         }
         id++;
     }
     closing.Set(true);
     Assert.IsTrue(sawAfterFlush.Get());
     w.Dispose();
     dir.Dispose();
 }
开发者ID:WakeflyCBass,项目名称:lucenenet,代码行数:42,代码来源:TestIndexWriterDelete.cs


示例12: testConcurrentAddWidgets

 public void testConcurrentAddWidgets()
 {
     WidgetBuilder widgetBuilder =
     new WidgetBuilder(new Class[] {   });
     //www.it - ebooks.infoGood Comments
     String text = "'''bold text'''";
     ParentWidget parent = null;
     AtomicBoolean failFlag = new AtomicBoolean();
     failFlag.set(false);
     //This is our best attempt to get a race condition
     //by creating large number of threads.
     for (int i = 0; i < 25000; i++)
     {
         WidgetBuilderThread widgetBuilderThread =
         new WidgetBuilderThread(widgetBuilder, text, parent, failFlag);
         Thread thread = new Thread(new ThreadStart(assertEquals));
         thread.Start();
     }
     assertEquals(false, failFlag.get());
 }
开发者ID:mikemajesty,项目名称:Livro-CleanCode,代码行数:20,代码来源:Explanation-of-Intent.cs


示例13: startRecordRig

        private void startRecordRig()
        {
            recordedRigs = new List<Body[]>();
            recordedRigTimePoints = new List<int>();
            rigDetected = new AtomicBoolean(false);

            try
            {
                XmlWriterSettings ws = new XmlWriterSettings();
                ws.Indent = true;

                rigWriter = XmlWriter.Create(tempRigFileName, ws);
                rigWriter.WriteStartDocument();
                rigWriter.WriteStartElement("BodyDataSequence");
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
开发者ID:tuandnvn,项目名称:ecat,代码行数:20,代码来源:RecordPanel.Control.RecordRig.cs


示例14: SetValue_ManyConcurrentThreads_OnlyOneSucceeds_Test

        public void SetValue_ManyConcurrentThreads_OnlyOneSucceeds_Test()
        {
            _atomicBoolean = new AtomicBoolean(false);
            int totalSucceedingThreads = 0;

            Parallel.For(1, 11, (state) =>
            {
                System.Console.WriteLine(String.Format("Executing SetValue on thread {0}",
                    Thread.CurrentThread.ManagedThreadId));
                if (!_atomicBoolean.SetValue(true))
                {
                    System.Console.WriteLine(String.Format("Thread {0} was successful in calling SetValue.",
                        Thread.CurrentThread.ManagedThreadId));
                    Interlocked.Increment(ref totalSucceedingThreads);
                }
            });

            //Assert
            _atomicBoolean.Value.Should().BeTrue();
            totalSucceedingThreads.Should().Be(1);
        }
开发者ID:sachurao,项目名称:FinSharp,代码行数:21,代码来源:AtomicBooleanFixture.cs


示例15: ThreadAnonymousInnerClassHelper

 public ThreadAnonymousInnerClassHelper(TestDocValuesIndexing outerInstance, IndexWriter w, CountdownEvent startingGun, AtomicBoolean hitExc, Document doc)
 {
     this.OuterInstance = outerInstance;
     this.w = w;
     this.StartingGun = startingGun;
     this.HitExc = hitExc;
     this.Doc = doc;
 }
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:8,代码来源:TestDocValuesIndexing.cs


示例16: TestMixedTypesDifferentThreads

        public virtual void TestMixedTypesDifferentThreads()
        {
            Directory dir = NewDirectory();
            IndexWriter w = new IndexWriter(dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random())));

            CountdownEvent startingGun = new CountdownEvent(1);
            AtomicBoolean hitExc = new AtomicBoolean();
            ThreadClass[] threads = new ThreadClass[3];
            for (int i = 0; i < 3; i++)
            {
                Field field;
                if (i == 0)
                {
                    field = new SortedDocValuesField("foo", new BytesRef("hello"));
                }
                else if (i == 1)
                {
                    field = new NumericDocValuesField("foo", 0);
                }
                else
                {
                    field = new BinaryDocValuesField("foo", new BytesRef("bazz"));
                }
                Document doc = new Document();
                doc.Add(field);

                threads[i] = new ThreadAnonymousInnerClassHelper(this, w, startingGun, hitExc, doc);
                threads[i].Start();
            }

            startingGun.Signal();

            foreach (ThreadClass t in threads)
            {
                t.Join();
            }
            Assert.IsTrue(hitExc.Get());
            w.Dispose();
            dir.Dispose();
        }
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:40,代码来源:TestDocValuesIndexing.cs


示例17: ThreadAnonymousInnerClassHelper

 public ThreadAnonymousInnerClassHelper(TestTaxonomyCombined outerInstance, Lucene.Net.Facet.Taxonomy.FacetLabel abPath, int abOrd, int abYoungChildBase1, int abYoungChildBase2, int retry, DirectoryTaxonomyReader tr, AtomicBoolean stop, Exception[] error, int[] retrieval)
     : base("Child Arrays Verifier")
 {
     this.outerInstance = outerInstance;
     this.abPath = abPath;
     this.abOrd = abOrd;
     this.abYoungChildBase1 = abYoungChildBase1;
     this.abYoungChildBase2 = abYoungChildBase2;
     this.retry = retry;
     this.tr = tr;
     this.stop = stop;
     this.error = error;
     this.retrieval = retrieval;
 }
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:14,代码来源:TestTaxonomyCombined.cs


示例18: AssertConsistentYoungestChild

        private void AssertConsistentYoungestChild(FacetLabel abPath, int abOrd, int abYoungChildBase1, int abYoungChildBase2, int retry, int numCategories)
        {
            var indexDir = new SlowRAMDirectory(-1, null); // no slowness for intialization
            var tw = new DirectoryTaxonomyWriter(indexDir);
            tw.AddCategory(new FacetLabel("a", "0"));
            tw.AddCategory(abPath);
            tw.Commit();

            var tr = new DirectoryTaxonomyReader(indexDir);
            for (int i = 0; i < numCategories; i++)
            {
                var cp = new FacetLabel("a", "b", Convert.ToString(i));
                tw.AddCategory(cp);
                Assert.AreEqual(TaxonomyReader.INVALID_ORDINAL, tr.GetOrdinal(cp), "Ordinal of " + cp + " must be invalid until Taxonomy Reader was refreshed");
            }
            tw.Dispose();

            var stop = new AtomicBoolean(false);
            Exception[] error = new Exception[] { null };
            int[] retrieval = new int[] { 0 };

            var thread = new ThreadAnonymousInnerClassHelper(this, abPath, abOrd, abYoungChildBase1, abYoungChildBase2, retry, tr, stop, error, retrieval);
            thread.Start();

            indexDir.SleepMillis = 1; // some delay for refresh
            var newTaxoReader = TaxonomyReader.OpenIfChanged(tr);
            if (newTaxoReader != null)
            {
                newTaxoReader.Dispose();
            }

            stop.Set(true);
            thread.Join();
            Assert.Null(error[0], "Unexpcted exception at retry " + retry + " retrieval " + retrieval[0] + ": \n" + stackTraceStr(error[0]));

            tr.Dispose();
        }
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:37,代码来源:TestTaxonomyCombined.cs


示例19: IndexWriterAnonymousInnerClassHelper

 public IndexWriterAnonymousInnerClassHelper(TestIndexWriterDelete outerInstance, Directory dir, IndexWriterConfig setReaderPooling, AtomicInteger docsInSegment, AtomicBoolean closing, AtomicBoolean sawAfterFlush)
     : base(dir, setReaderPooling)
 {
     this.OuterInstance = outerInstance;
     this.DocsInSegment = docsInSegment;
     this.Closing = closing;
     this.SawAfterFlush = sawAfterFlush;
 }
开发者ID:paulirwin,项目名称:lucene.net,代码行数:8,代码来源:TestIndexWriterDelete.cs


示例20: ConcurrentMergeSchedulerAnonymousInnerClassHelper

 public ConcurrentMergeSchedulerAnonymousInnerClassHelper(TestConcurrentMergeScheduler outerInstance, int maxMergeCount, CountdownEvent enoughMergesWaiting, AtomicInteger runningMergeCount, AtomicBoolean failed)
 {
     this.OuterInstance = outerInstance;
     this.MaxMergeCount = maxMergeCount;
     this.EnoughMergesWaiting = enoughMergesWaiting;
     this.RunningMergeCount = runningMergeCount;
     this.Failed = failed;
 }
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:8,代码来源:TestConcurrentMergeScheduler.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# AtomicComposition类代码示例发布时间:2022-05-24
下一篇:
C# AtomCollection类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap