Esempio n. 1
0
        //
        // Starts the test.
        //

        internal static Action Run()
        {
            queue = new StUnboundedBlockingQueue <int>(true);
            // queue = new StBoundedBlockingQueue<int>(4 * 1024, true);
            // queue = new StArrayBlockingQueue<int>(4 * 1024, true);

            StRegisteredTake <int> regTake = queue.RegisterTake(TakeCallback <int>, null, 250, false);

            for (int i = 0; i < PRODUCERS; i++)
            {
                new Producer().Start(i, "p #" + i);
            }

            Action stop = () => {
                shutdown.Set();
                done.WaitOne();
                long ps = 0;
                for (int i = 0; i < PRODUCERS; i++)
                {
                    ps += productions[i];
                }
                VConsole.WriteLine("+++ Total: prods = {0}, cons = {1}", ps, consumptions);
                //regTake.Unregister();
            };

            return(stop);
        }
Esempio n. 2
0
        //
        // The take consumer callback
        //

        private static void TakeCallback <T>(object state, T di, bool timedOut)
        {
            StRegisteredTake <T> regTake = (StRegisteredTake <T>)state;

            if (timedOut)
            {
                Console.WriteLine("+++TIMEOUT!");
            }
            else
            {
                consumptions++;
            }
        }