Esempio n. 1
0
        public ParallelWorker(int workerCount)
        {
            if (workerCount < 1) throw new ArgumentException(nameof(workerCount));

            this.syncRoot = new object();
            this.capacity = workerCount;
            this.idleWorkers = ImmutableHashSet<int>.Empty.Union(Enumerable.Range(0, workerCount));
            this.busyWorkers = ImmutableHashSet<int>.Empty;

            this.waitingWorkItems = new CancellableQueue<WaitingWorkItem>();
        }
Esempio n. 2
0
 public IdleDetector()
 {
     syncRoot = new object();
     referenceCount = 0;
     waiters = new CancellableQueue<Waiter>();
 }
 static void DoTest(Action<CancellableQueue<int, string>, CancellationTokenSource> action)
 {
     using (CancellationTokenSource cts = new CancellationTokenSource())
     {
         using (var q = new CancellableQueue<int, string>(i => i.ToString()))
         {
             action(q, cts);
         }
     }
 }