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


C# Barrier.AddParticipant方法代码示例

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


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

示例1: BarrierLimitedModeCharacterCounter

        public BarrierLimitedModeCharacterCounter(ITextFile textFile, Barrier barrier)
        {
            this.barrier = barrier;
            barrier.AddParticipant();

            charCounts = new Lazy<IReadOnlyDictionary<char, int>>(() => BufferAndCount(textFile));
        }
开发者ID:peterchase,项目名称:parallel-workshop,代码行数:7,代码来源:BarrierLimitedModeCharacterCounter.cs

示例2: Main

        static void Main()
        {
            const int numberTasks = 2;
            const int partitionSize = 1000000;
            const int loops = 5;
            var taskResults = new Dictionary<int, int[][]>();
            var data = new List<string>[loops];
            for (int i = 0; i < loops; i++)
            {
                data[i] = new List<string>(FillData(partitionSize * numberTasks));
            }

            var barrier = new Barrier(1);
            LogBarrierInformation("initial participants in barrier", barrier);

            for (int i = 0; i < numberTasks; i++)
            {
                barrier.AddParticipant();

                int jobNumber = i;
                taskResults.Add(i, new int[loops][]);
                for (int loop = 0; loop < loops; loop++)
                {
                    taskResults[i][loop] = new int[26];
                }
                WriteLine($"Main - starting task job {jobNumber}");
                Task.Run(() => CalculationInTask(jobNumber, partitionSize, barrier, data, loops, taskResults[jobNumber]));
            }

            for (int loop = 0; loop < 5; loop++)
            {
                LogBarrierInformation("main task, start signaling and wait", barrier);
                barrier.SignalAndWait();
                LogBarrierInformation("main task waiting completed", barrier);
                //                var resultCollection = tasks[0].Result.Zip(tasks[1].Result, (c1, c2) => c1 + c2);
                int[][] resultCollection1 = taskResults[0];
                int[][] resultCollection2 = taskResults[1];
                var resultCollection = resultCollection1[loop].Zip(resultCollection2[loop], (c1, c2) => c1 + c2);

                char ch = 'a';
                int sum = 0;
                foreach (var x in resultCollection)
                {
                    WriteLine($"{ch++}, count: {x}");
                    sum += x;
                }

                LogBarrierInformation($"main task finished loop {loop}, sum: {sum}", barrier);
            }

            WriteLine("at the end");
            ReadLine();
        }
开发者ID:ProfessionalCSharp,项目名称:ProfessionalCSharp6,代码行数:53,代码来源:Program.cs

示例3: DownloadGDBFiles

        private void DownloadGDBFiles()
        {
            finishFirstGDBSemaphore = new SemaphoreSlim(1);
            //finishFirstGDBSemaphore.Wait();

            Barrier downloadTrainingBarrier = new Barrier(1);
            
            foreach (int key in _currentTraining.Playlist.Keys)
            {
                Exercise exercise = _currentTraining.Playlist[key][1];
                int newKey = key;
               
                if (exercise.IsTraceable && !exercise.Downloaded)
                {
                    downloadTrainingBarrier.AddParticipant();

                    if (newKey == FIRST_EXERCISE)
                    {
                        finishFirstGDBSemaphore.Wait();
                    }
                    Task downloadGDB = new Task(() => DownloadCurrentGDB(exercise, newKey, downloadTrainingBarrier));
                    downloadGDB.Start(); 
                }

            }

            downloadTrainingBarrier.SignalAndWait();
            _currentTraining.Downloaded = true;

            //watch.Stop();
            //var elapsedMs = watch.ElapsedMilliseconds;
            //Console.WriteLine("==> Downloading gdb " + elapsedMs.ToString());
        }
开发者ID:amirben,项目名称:VideoTherapy,代码行数:33,代码来源:TrainingMenu.xaml.cs

示例4: DownloadTreatment

        /// <summary>
        /// Download training preview images for the treatment screen
        /// </summary>
        public void DownloadTreatment()
        {
            //crearte dir for user (if not already created)
            //string newDir = CreateDir(dir, _patient.AccountId.ToString());
            //newDir = CreateDir(newDir, _patient.PatientTreatment.TreatmentNumber.ToString());
            string newDir = CreateDir(dir, "treatmentThumb");

            //initilaize the barrier
            int size = _patient.PatientTreatment.TrainingList.Count;
            //Barrier _barrier = new Barrier(size + 1);
            Barrier _barrier = new Barrier(1);

            for (int i = 0; i < size; i++)
            {
                int temp = i;

                string _from = _patient.PatientTreatment.TrainingList[temp].TrainingThumbs;
                string _to = newDir + "\\" + _patient.PatientTreatment.TrainingList[temp].TrainingId + ".png";
                _patient.PatientTreatment.TrainingList[temp].TrainingThumbs = _to;

                if (!File.Exists(_to))
                {
                    _barrier.AddParticipant();
                    Task tempThread = new Task(() =>
                    {
                        DownloadFile(_from, _to);
                        _barrier.SignalAndWait();
                    });
                    tempThread.Start();
                }

            }

            _barrier.SignalAndWait();

            _barrier.Dispose();
        }
开发者ID:amirben,项目名称:VideoTherapy,代码行数:40,代码来源:DownloadCache.cs

示例5: RunSimulation

        /*
         * Running the simulation
         * */
        private void RunSimulation()
        {
            int sideSize = (int)Math.Ceiling((double)_simulationField.GetLength(0) / (double)MAX_SECTOR_SIZE);
            int threadsCount = sideSize * sideSize;

            _barrier = new Barrier(0);
            while (true)
            {

                if (_barrier.ParticipantCount > 0)
                {
                    _barrier.SignalAndWait();
                }

                for (int sector = 0; sector <= threadsCount; sector++)
                {
                    _barrier.AddParticipant();
                    ThreadPool.QueueUserWorkItem(new WaitCallback(new Action<object>(DoSector)),
                       sector);
                }

                Thread.Sleep(200);
            }
        }
开发者ID:mgechev,项目名称:WaTor,代码行数:27,代码来源:Simulation.cs

示例6: SignalSimple

		public void SignalSimple ()
		{
			var barrier = new Barrier (0);
			barrier.AddParticipant ();
			Assert.IsTrue (barrier.SignalAndWait (500), "#1");
		}
开发者ID:JokerMisfits,项目名称:linux-packaging-mono,代码行数:6,代码来源:BarrierTest.cs

示例7: RunBarrierTest7_Bug603035

        private static bool RunBarrierTest7_Bug603035()
        {
            TestHarness.TestLog("*RunBarrierTest7_Bug603035");
            bool failed = false;
            for (int j = 0; j < 100 && !failed; j++)
            {
                Barrier b = new Barrier(0);
               
                Action[] actions = Enumerable.Repeat((Action)(() =>
                {
                    for (int i = 0; i < 400; i++)
                    {
                        try
                        {
                            b.AddParticipant();
                            b.RemoveParticipant();
                        }
                        catch
                        {
                            failed = true;
                            break;
                        }
                    }

                }), 4).ToArray();
                Parallel.Invoke(actions);
                if (b.ParticipantCount != 0)
                    failed = true;
            }

            if (failed)
            {
                TestHarness.TestLog("Bug603035 failed");
                return false;
            }
            TestHarness.TestLog("Bug603035 succeeded");
            return true;

        }
开发者ID:modulexcite,项目名称:IL2JS,代码行数:39,代码来源:BarrierTests.cs


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