Ejemplo n.º 1
0
            private void Terminate()
            {
                // Finish thread by setting null loop body and signaling about available task
                LoopFunction = null;
                int workerThreadCount = this.workerThreads.Count;

                for (int i = 0; i < workerThreadCount; i++)
                {
                    this.workerThreads[i].Terminate();
                }
            }
Ejemplo n.º 2
0
            /// <summary>
            /// Runs the ForEach loop.
            /// </summary>
            /// <param name="items">The items.</param>
            /// <param name="loopBody">The loop body.</param>
            public void DoForEach(IEnumerable <T> items, ForEachLoopDelegate loopBody)
            {
                this.enumerator   = items.GetEnumerator();
                this.LoopFunction = loopBody;

                // Signal waiting task to all threads and mark them not idle.
                for (int i = 0; i < this.threadCount; i++)
                {
                    WorkerThread workerThread = workerThreads[i];
                    workerThread.ThreadIdle.Reset();
                    workerThread.TaskWaiting.Set();
                }

                // Wait until all threads become idle
                for (int i = 0; i < this.threadCount; i++)
                {
                    WorkerThread workerThread = workerThreads[i];
                    workerThread.ThreadIdle.WaitOne();
                }
            }