SpawnThread() private method

Spawns a new thread and adds it to the thread pool.
private SpawnThread ( ) : void
return void
Esempio n. 1
0
 public void DoesNotDespawnWorkingThread( )
 {
     ThreadManager tm = new ThreadManager(0, 1, TimeSpan.MinValue, TimeSpan.MaxValue, 1, TimeSpan.FromMilliseconds(10));
     tm.SpawnThread();
     ActionTask task = new ActionTask(( _ ) => System.Threading.Thread.Sleep(500), false);
     tm.EnqueueTask(task);
     tm.UnsafeUpdate();
     System.Threading.Thread.Sleep(20);
     tm.UnsafeUpdate();
     Assert.AreEqual(1, tm.NumThreads, "Despawned a thread while working.");
 }
Esempio n. 2
0
        public void DestroysThreadsWhenOldEnough( )
        {
            tm.SpawnThread();
            System.Threading.Thread.Sleep(300);
            int cur_threads = tm.NumThreads;
            bool result = tm.DespawnThreadIfNeeded();
            Assert.IsTrue(result, "Did not report that it despawned a thread.");
            Assert.IsTrue(cur_threads > tm.NumThreads, "Did not actually despawn a thread.");

            ThreadManager tm2 = new ThreadManager(TimeSpan.MinValue, TimeSpan.MaxValue, 100, TimeSpan.FromMilliseconds(1));
            tm2.SpawnThread();
            cur_threads = tm2.NumThreads;
            System.Threading.Thread.Sleep(10);
            result = tm2.DespawnThreadIfNeeded();
            Assert.IsTrue(result, "Did not report that it despawned a thread.");
            Assert.IsTrue(cur_threads > tm2.NumThreads, "Did not actually despawn a thread.");
        }