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


C# AtomicBoolean类代码示例

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


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


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