BEPUphysics.Threading.SpecializedThreadManager.AddThread C# (CSharp) Method

AddThread() public method

Adds a new worker thread to the engine.
public AddThread ( Action initialization, object initializationInformation ) : void
initialization Action Function that each of the new threads will call before entering its work loop. Note that this type of thread manager spawns two worker threads for each given thread; /// the initializer will run twice.
initializationInformation object Data to give the initializer.
return void
        public void AddThread(Action<object> initialization, object initializationInformation)
        {
            taskManager.AddThread(initialization, initializationInformation);
            loopManager.AddThread(initialization, initializationInformation);
        }

Same methods

SpecializedThreadManager::AddThread ( ) : void

Usage Example

        /// <summary>
        /// Constructs a new demo.
        /// </summary>
        /// <param name="game">Game owning this demo.</param>
        public MultithreadedScalingTestDemo(DemosGame game)
            : base(game)
        {
            simulationBuilders = new Func<Space, int>[]
                                     {
                                         BuildPileSimulation,
                                         BuildWallSimulation,
                                         BuildPlanetSimulation
                                     };

            #if WINDOWS
            int coreCountMax = Environment.ProcessorCount;

            testResults = new double[coreCountMax, simulationBuilders.Length];

            int reruns = 1;
            for (int i = 0; i < reruns; i++)
            {
                GC.Collect();
                var threadManager = new SpecializedThreadManager();

                //Try different thread counts.
                for (int j = 0; j < coreCountMax; j++)
                {
                    threadManager.AddThread();
                    for (int k = 0; k < simulationBuilders.Length; k++)
                        testResults[j, k] = RunTest(threadManager, simulationBuilders[k]);
                    GC.Collect();

                }
            }
            #else
            testResults = new double[4, simulationBuilders.Length];
            int reruns = 10;
            for (int i = 0; i < reruns; i++)
            {
                GC.Collect();
                var threadManager = new SpecializedThreadManager();

                threadManager.AddThread(delegate { Thread.CurrentThread.SetProcessorAffinity(new[] { 1 }); }, null);

                for (int k = 0; k < simulationBuilders.Length; k++)
                    testResults[0, k] += RunTest(threadManager, simulationBuilders[k]);
                GC.Collect();

                threadManager.AddThread(delegate { Thread.CurrentThread.SetProcessorAffinity(new[] { 3 }); }, null);
                for (int k = 0; k < simulationBuilders.Length; k++)
                    testResults[1, k] += RunTest(threadManager, simulationBuilders[k]);
                GC.Collect();
                threadManager.AddThread(delegate { Thread.CurrentThread.SetProcessorAffinity(new[] { 5 }); }, null);
                for (int k = 0; k < simulationBuilders.Length; k++)
                    testResults[2, k] += RunTest(threadManager, simulationBuilders[k]);
                GC.Collect();
                threadManager.AddThread(delegate { Thread.CurrentThread.SetProcessorAffinity(new[] { 4 }); }, null);
                for (int k = 0; k < simulationBuilders.Length; k++)
                    testResults[3, k] += RunTest(threadManager, simulationBuilders[k]);
                GC.Collect();
            }
            #endif
        }
All Usage Examples Of BEPUphysics.Threading.SpecializedThreadManager::AddThread