Exemple #1
0
        public void SimpleContinueWithTest()
        {
            threadPool = new MyThreadPool(1);
            var task = threadPool.Submit <int>(() => 2 * 2).ContinueWith(x => x * 3);

            Assert.AreEqual(12, task.Result);
            Assert.IsTrue(task.IsCompleted);
        }
Exemple #2
0
        public void ContinueWorkAfterShutdownTest()
        {
            threadPool = new MyThreadPool(2);
            var task1 = threadPool.Submit(() => 5 * 7);

            threadPool.Shutdown();
            Assert.Throws <InvalidOperationException>(() => threadPool.Submit(() => 2 + 1));
        }
Exemple #3
0
        public void CorrectNumberOfThreadsTest()
        {
            int    countOfThreads = 0;
            Object locker         = new object();

            threadPool = new MyThreadPool(Environment.ProcessorCount);
            for (int iter = 0; iter < 7; iter++)
            {
                threadPool.Submit(() =>
                {
                    lock (locker)
                    {
                        countOfThreads++;
                        Thread.Sleep(30);
                        return(1);
                    }
                });
            }
            Thread.Sleep(700);
            Assert.IsTrue(Environment.ProcessorCount <= countOfThreads);
        }
 public MyTask(Func <TResult> func, MyThreadPool threadPool)
 {
     this.threadPool           = threadPool;
     this.func                 = func;
     this.submitFunctionsQueue = new Queue <Action>();
 }
Exemple #5
0
 public void SetUp()
 {
     threadPool = new MyThreadPool(Environment.ProcessorCount);
 }