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


C# ConcurrentStack.Clear方法代码示例

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


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

示例1: verify_bahaviour_for_concurrent_access_under_identical_keys

        public void verify_bahaviour_for_concurrent_access_under_identical_keys()
        {
            var keys = new[] {"a", "a"};
            var counter = new ConcurrentStack<int>();
            var storage = new ConcurrentStack<TestItem>();

            // first run
            var threads = MakeThreads(keys);
            threads.ForEach(t => t.Start(new object[] {storage, counter}));
            threads.ForEach(t => t.Join());

            Assert.Equal(1, counter.Count);
            Assert.Equal(2, storage.Count);
            var a = storage.First();
            Assert.Same(storage.First(), storage.Last());

            // cleanups and second run
            storage.Clear();
            counter.Clear();

            threads = MakeThreads(keys);
            threads.ForEach(t => t.Start(new object[] {storage, counter}));
            threads.ForEach(t => t.Join());

            Assert.Equal(0, counter.Count);
            Assert.Equal(2, storage.Count);
            var aa = storage.First();
            Assert.Same(storage.First(), storage.Last());
            Assert.Same(a, aa);
        }
开发者ID:jwaliszko,项目名称:ExpressiveAnnotations,代码行数:30,代码来源:ProcessStorageTest.cs

示例2: verify_bahaviour_for_concurrent_access_under_different_keys

        public void verify_bahaviour_for_concurrent_access_under_different_keys()
        {
            var keys = new[] {"a", "b"};
            var counter = new ConcurrentStack<int>(); // value factory threads
            var storage = new ConcurrentStack<TestItem>(); // cached items

            // first run
            var threads = MakeThreads(keys);
            threads.ForEach(t => t.Start(new object[] {storage, counter}));
            threads.ForEach(t => t.Join());

            Assert.Equal(2, counter.Count);
            Assert.Equal(2, storage.Count);
            Assert.NotSame(storage.First(), storage.Last());
            var a = storage.FirstOrDefault(x => x.Id == "a");
            var b = storage.FirstOrDefault(x => x.Id == "b");

            // cleanups and second run
            storage.Clear();
            counter.Clear();

            threads = MakeThreads(keys);
            threads.ForEach(t => t.Start(new object[] {storage, counter}));
            threads.ForEach(t => t.Join());

            Assert.Equal(0, counter.Count);
            Assert.Equal(2, storage.Count);
            Assert.NotSame(storage.First(), storage.Last());
            var aa = storage.FirstOrDefault(x => x.Id == "a");
            var bb = storage.FirstOrDefault(x => x.Id == "b");
            Assert.Same(a, aa);
            Assert.Same(b, bb);
        }
开发者ID:jwaliszko,项目名称:ExpressiveAnnotations,代码行数:33,代码来源:ProcessStorageTest.cs

示例3: CreateBlock

    public static ActionBlock<StatsdMessage> CreateBlock(ITargetBlock<Bucket> target,
      IIntervalService intervalService)
    {
      var rawLines = new ConcurrentStack<Raw>();
      var incoming = new ActionBlock<StatsdMessage>(p =>
        {
          rawLines.Push(p as Raw);
        },
        Utility.UnboundedExecution());

      intervalService.Elapsed += (sender, e) =>
        {
          if (rawLines.Count == 0)
          {
            return;
          }
          var lines = rawLines.ToArray();
          rawLines.Clear();
          var bucket = new RawBucket(lines, e.Epoch);
          target.Post(bucket);
        };
      return incoming;
    }
开发者ID:houcine,项目名称:statsd.net,代码行数:23,代码来源:PassThroughBlockFactory.cs

示例4: RunConcurrentStackTest3_Clear

        // Just validates clearing the stack's contents.
        private static bool RunConcurrentStackTest3_Clear(int count)
        {
            TestHarness.TestLog("* RunConcurrentStackTest3_Clear()");

            ConcurrentStack<int> s = new ConcurrentStack<int>();
            for (int i = 0; i < count; i++)
                s.Push(i);

            s.Clear();

            bool isEmpty = s.IsEmpty;
            int sawCount = s.Count;

            TestHarness.TestLog("  > IsEmpty={0}, Count={1}", isEmpty, sawCount);

            return isEmpty && sawCount == 0;
        }
开发者ID:modulexcite,项目名称:IL2JS,代码行数:18,代码来源:CdsTests.cs

示例5: Test3_Clear

        // Just validates clearing the stack's contents.
        private static void Test3_Clear(int count)
        {
            ConcurrentStack<int> s = new ConcurrentStack<int>();
            for (int i = 0; i < count; i++)
                s.Push(i);

            s.Clear();

            Assert.True(s.IsEmpty);
            Assert.Equal(0, s.Count);
        }
开发者ID:ChuangYang,项目名称:corefx,代码行数:12,代码来源:ConcurrentStackTests.cs

示例6: Validate_Solutions

 private void Validate_Solutions(double Removal_Ratio)
 {
     Solution_List_Threading = new ConcurrentStack<Solution>() { };
     List<Solution> Holder = new List<Solution>() { };
     count = Convert.ToInt32(Solution_List.Count * (1 - Removal_Ratio));
     int Count_Original = count;
     for (int n = 0; n < Count_Original; n++)
     {
         using (e = new CountdownEvent(NumberOfThreads))
         {
             for (int i = 0; i < NumberOfThreads; i++)
             {
                 ThreadPool.QueueUserWorkItem(new WaitCallback(Validate_Solutions), i);
             }
             e.Wait();
         }
         int max = -1;
         int mx = -1;
         for (int i = 0; i < Solution_List_Threading.Count; i++)
         {
             if (max < Solution_List_Threading.ElementAt(i).Unknowns_Sum)
             {
                 max = Solution_List_Threading.ElementAt(i).Unknowns_Sum;
                 mx = i;
             }
         }
         Holder.Add(new Solution(Solution_List_Threading.ElementAt(mx)));
         Solution_List_Threading.Clear();
         Solution_List.RemoveAt(mx);
         count = Convert.ToInt32(Solution_List.Count * (1 - Removal_Ratio));
     }
     Solution_List = new List<Solution>(Holder); Holder.Clear();
 }
开发者ID:kaskanoidas,项目名称:MOAL,代码行数:33,代码来源:Genetic_Algorithm.cs

示例7: FaceNodeSpliting


//.........这里部分代码省略.........
                {
                    return fa1.Min_Y.CompareTo(fa2.Min_Y);
                });

                // get the y median value
                faceNode.Y_mid = faceNode.FaceList[(int)Math.Truncate(faceNode.FaceList.Count / 2.0f)].Max_Y;

            #else
                float max_X= float.MinValue,min_X= float.MaxValue;
                float max_Y= float.MinValue,min_Y= float.MaxValue;

                foreach (Face fa in faceNode.FaceList)
                {
                    // get the max x
                    if (max_X < fa.Max_X)
                        max_X = fa.Max_X;

                    // get the min x
                    if (min_X > fa.Min_X)
                        min_X = fa.Min_X;

                    // get the max Y
                    if (max_Y < fa.Max_Y)
                        max_Y = fa.Max_Y;

                    // get the min Y
                    if (min_Y > fa.Min_Y)
                        min_Y = fa.Min_Y;
                }

                // get the mid value
                faceNode.X_mid = (min_X + max_X ) / 2;
                faceNode.Y_mid = (min_Y + max_Y) / 2;
            #endif

                // create the 4 leaf
                faceNode.UpLeft = new FaceDistTreeNode();
                faceNode.DownLeft = new FaceDistTreeNode();
                faceNode.UpRight = new FaceDistTreeNode();
                faceNode.DownRight = new FaceDistTreeNode();

                // disable the leaf mode of the node
                faceNode.isLeaf = false;

                // the faces that is going to remain to this node
                ConcurrentStack<Face> remain = new ConcurrentStack<Face>();

                // fill the nodes
                foreach (Face fa in faceNode.FaceList)
                {
                    if (fa.Min_X > faceNode.X_mid)
                    {
                        if (fa.Min_Y > faceNode.Y_mid)
                        {
                            faceNode.UpRight.FaceList.Add(fa);
                        }
                        else if (fa.Max_Y < faceNode.Y_mid)
                        {
                            faceNode.DownRight.FaceList.Add(fa);
                        }
                        else
                        {
                            // add in both sides :P
                            remain.Push(fa);
                        }
                    }
                    else if (fa.Max_X < faceNode.X_mid)
                    {
                        if (fa.Min_Y > faceNode.Y_mid)
                        {
                            faceNode.UpLeft.FaceList.Add(fa);
                        }
                        else if (fa.Max_Y < faceNode.Y_mid)
                        {
                            faceNode.DownLeft.FaceList.Add(fa);
                        }
                        else
                        {
                            // add in both sides :P
                            remain.Push(fa);
                        }

                    }
                    else
                    {
                        remain.Push(fa);
                    }
                }

                // clean the list
                faceNode.FaceList.Clear();

                // add the remain faces to the node list
                faceNode.FaceList.AddRange(remain);

                // clean the stack
                remain.Clear();

            }
        }
开发者ID:fxbit,项目名称:FxMath,代码行数:101,代码来源:FaceDistMixTree.cs


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