예제 #1
0
        static void Main(string[] args)
        {
            /**
             * Invocation Requests are placed in this buffer to be managed in a circular way
             * 5 threads
             * 10 requests (buffer size)
             */
            const int nThreads  = 5;
            const int nRequests = 10;

            ThrPool tpool = new ThrPool(nThreads, nRequests);

            /** Delegate */
            for (int i = 0; i < (nRequests / 2); i++)
            {
                A a = new A(i);
                tpool.AssyncInvoke(new ThrWork(a.DoWorkA));
                B b = new B(i);
                tpool.AssyncInvoke(new ThrWork(b.DoWorkB));
            }
            Console.ReadLine();

            /** stops threads from reading requests */
            tpool.Running = false;
            EndProgram end = new EndProgram();

            for (int thread = 0; thread < nThreads; thread++)
            {
                tpool.AssyncInvoke(new ThrWork(end.End));
            }
        }
예제 #2
0
파일: Program.cs 프로젝트: Opty-MSc/DIDA
        static void Main()
        {
            ThrPool pool = new ThrPool(5, 10);

            int i = 0;

            while (i < 20)
            {
                A a = new A(i);
                pool.AssyncInvoke(new ThreadStart(a.DoWorkA));
                Console.WriteLine("Invoke Number: {0}!", ++i);

                B b = new B(i);
                pool.AssyncInvoke(new ThreadStart(b.DoWorkB));
                Console.WriteLine("Invoke Number: {0}!", ++i);
            }
        }