UnsafeUpdate() private method

Checks for new work in the Queue and sends it out, checks for spawning and despawning threads.
private UnsafeUpdate ( ) : void
return void
Ejemplo n.º 1
0
 /// <summary>
 /// Unity's update loop. All we need to do is update the managers.
 /// </summary>
 internal void Update( )
 {
     // Maybe the threadManager should be moved to its own thread.
     threadManager.UnsafeUpdate();
     unityManager.UnsafeUpdate();
 }
Ejemplo n.º 2
0
        public void LetsOthersUseNappingThreadsCorrectly( )
        {
            int i = 0;
            object _lock = new object();
            ThreadManager tman = new ThreadManager(1, 1);
            // Using this to test interaction very specifically.
            tman.WaitForThreadSpawns();
            ActionTask task = new ActionTask(( _ ) =>
            {
                _.IsNapping = true;
            }, false);
            task.Extend(( _ ) => i = 100);
            tman.EnqueueTask(task);
            for ( int j = 0; j < 10; j++ )
                tman.EnqueueTask(new ActionTask(( _ ) =>
                {
                    lock ( _lock )
                        i++;
                }, false));

            tman.UnsafeUpdate();
            for ( int j = 0; j < 100; j++ )
                if ( task.IsNapping )
                    break;
                else
                    System.Threading.Thread.Sleep(1);

            for ( int j = 0; j < 10; j++ )
            {
                tman.UnsafeUpdate();
                System.Threading.Thread.Sleep(1);
                lock ( _lock ) Assert.AreEqual(j + 1, i, "Ran some number other than 1 of the Tasks at once on update #" + j);
            }

            task.IsNapping = false;
            tman.UnsafeUpdate();
            System.Threading.Thread.Sleep(1);
            Assert.AreEqual(100, i, "Did not run awakened Task.");

            tman.Dispose();
        }
Ejemplo n.º 3
0
        public void RunsWaitingTasksCorrectly( )
        {
            int i = 0;
            tm = new ThreadManager(2, 2);
            for ( int j = 0; j < 10; j++ )
                tm.EnqueueTask(new ActionTask(( _ ) => i++, false));

            for ( int j = 2; j <= 10; j += 2 )
            {
                tm.UnsafeUpdate();
                System.Threading.Thread.Sleep(10);
                Assert.AreEqual(j, i, "Ran some number other than 2 of the Tasks at once on update #" + j / 2);
            }
        }
Ejemplo n.º 4
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.");
 }