protected void ParallelBranch()
        {
            int processor = Environment.ProcessorCount;
            int loopCount = processor;

            while (loopCount-- > 0)
            {
                IMHComputeNode <T> n = null;
                if (!forBranching_.TryGet(out n))
                {
                    return;
                }
                ;
                BranchNode(n);
            }

            Thread[] threads = new Thread[processor];
            for (int I = 0; I < processor; I++)
            {
                threads[I] = new Thread(
                    () => {
                    while (true)
                    {
                        IMHComputeNode <T> n = null;
                        if (!forBranching_.TryGet(out n))
                        {
                            break;
                        }
                        ;
                        BranchNode(n);
                    }
                }
                    );
                threads[I].Name = $"MHComputeTree Branching: {I}";
                threads[I].Start();
            }
            foreach (Thread t in threads)
            {
                t.Join(TimeSpan.FromMilliseconds(sectionTimeOut));
            }
        }
Example #2
0
        protected override Thread GetThread()
        {
            Thread t = new Thread(
                () => {
                while (true)
                {
                    Task task = null;
                    if (!tasks_.TryGet(out task))
                    {
                        return;
                    }
                    task.Start();
                }
            }
                );

            return(t);
        }