private void Run()
            {
                VConsole.WriteLine("+++ soc #{0} started...", id);
                int request = id;
                int fails   = 0;

                do
                {
                    try {
                        while (!channel.Send(request, new StCancelArgs(1, shutdown)))
                        {
                            fails++;
                        }
                        if ((++requests[id] % 10000) == 0)
                        {
                            VConsole.Write("-so{0}", id);
                        }
                    } catch (StThreadAlertedException) {
                        break;
                    }
                    if (++request < 0)
                    {
                        request = id;
                    }
                } while (!shutdown.IsSet);
                VConsole.WriteLine("+++ soc #{0} exiting: [{1}/{2}]",
                                   id, requests[id], fails);
                done.Signal();
            }
Esempio n. 2
0
            private void Run()
            {
                VConsole.WriteLine("+++ a #{0} started...", id);
                int fail = 0;
                int index;

                do
                {
                    try {
                        index = StWaitable.WaitAny(ss, new StCancelArgs(1, shutdown));
                        if (index >= 0 && index < SEMAPHORES)
                        {
                            if ((++acquires[id] % 500) == 0)
                            {
                                VConsole.Write("-{0}", id);
                            }
                        }
                        else
                        {
                            fail++;
                        }
                    } catch (StThreadAlertedException) {
                        break;
                    }
                    //Thread.Sleep(0);
                } while (!shutdown.IsSet);
                VConsole.WriteLine("+++ a #{0} exiting, [{1}/{2}]", id, acquires[id], fail);
                done.Signal();
            }
Esempio n. 3
0
            private void Run()
            {
                VConsole.WriteLine("+++ rd #{0} started...", id);
                Random r    = new Random((id + 1) * Environment.TickCount);
                int    fail = 0;

                do
                {
                    try {
                        if (rwl.TryEnterRead(new StCancelArgs(r.Next(10) + 1, shutdown)))
                        {
                            if ((++reads[id] % 20000) == 0)
                            {
                                VConsole.Write("-r{0}", id);
                            }
                            rwl.ExitRead();
                        }
                        else
                        {
                            fail++;
                        }
                    } catch (StThreadAlertedException) {
                        break;
                    }
                } while (!shutdown.IsSet);
                VConsole.WriteLine("+++ rd #{0} exiting: [{1}/{2}]", id, reads[id], fail);
                done.Signal();
            }
            private void Run()
            {
                int request;
                StRendezvousToken token;
                int fails = 0;

                VConsole.WriteLine("+++ svr #{0} started...", id);
                do
                {
                    try {
                        while (!channel.Receive(out request, out token,
                                                new StCancelArgs(1, shutdown)))
                        {
                            fails++;
                        }
                        if (token.ExpectsReply)
                        {
                            channel.Reply(token, request);
                        }
                        if ((++services[id] % 10000) == 0)
                        {
                            VConsole.Write("-s{0}", id);
                        }
                    } catch (StThreadAlertedException) {
                        break;
                    }
                    //Thread.Sleep(1);
                } while (!shutdown.IsSet);
                VConsole.WriteLine("+++ svr #{0} exiting: [{1}/{2}]", id, services[id], fails);
                done.Signal();
            }
            private void Run()
            {
                int fail = 0;

                StWaitable[] ws = new StWaitable[] { s };
                VConsole.WriteLine("+++ a #{0} started...", id);
                do
                {
                    try {
                        while (!s.Wait(1, new StCancelArgs((id & 1) + 1, shutdown)))
                        {
                            //while (!s.Wait(new StCancelArgs((n & 1) + 1, shutdown))) {
                            //while (StWaitable.WaitAny(ws, new StCancelArgs((n & 1) + 1, shutdown)) == StParkStatus.Timeout) {
                            //while (!StWaitable.WaitAll(ws, new StCancelArgs((n & 1) + 10, shutdown))) {
                            if (shutdown.IsSet)
                            {
                                goto Exit;
                            }
                            fail++;
                            //Thread.Sleep(0);
                        }
                    } catch (StThreadAlertedException) {
                        break;
                    }
                    if ((++acquires[id] % 20000) == 0)
                    {
                        VConsole.Write("-{0}", id);
                    }
                } while (!shutdown.IsSet);
Exit:
                VConsole.WriteLine("+++ acquirer #{0} exiting: [{1}/{2}]",
                                   id, acquires[id], fail);
                done.Signal();
            }
            private void Run()
            {
                VConsole.WriteLine("+++ c #{0} started...", id);
                int fail = 0;
                int rmsg;

                do
                {
                    try {
                        while (!queue.TryTake(out rmsg, new StCancelArgs(1, shutdown)))
                        {
                            //while (StBlockingQueue<int>.TryTakeAny(new StBlockingQueue<int>[]{queue},
                            //           out rmsg, new StCancelArgs(1, shutdown)) == StParkStatus.Timeout) {
                            fail++;
                        }
                        if ((++consumptions[id] % 20000) == 0)
                        {
                            VConsole.Write("-c{0}", id);
                        }
                    } catch (StThreadAlertedException) {
                        while (queue.TryTake(out rmsg, new StCancelArgs(20)))
                        {
                            consumptions[id]++;
                        }
                        break;
                    }
                } while (true);
                VConsole.WriteLine("+++ c #{0} exiting: [{1}/{2}]",
                                   id, consumptions[id], fail);
                done.Signal();
            }
            private void Run()
            {
                VConsole.WriteLine("+++ c #{0} started...", id);
                Random r    = new Random((id + 1) * Environment.TickCount);
                int    fail = 0;

                do
                {
                    try {
                        string data;
                        if (q.Poll(out data, new StCancelArgs(r.Next(2), shutdown)))
                        {
                            if ((++cons[id] % 10000) == 0)
                            {
                                VConsole.Write("-c{0}", id);
                            }
                        }
                        else
                        {
                            fail++;
                        }
                    } catch (StThreadAlertedException) {
                        break;
                    }
                } while (true);
                VConsole.WriteLine("+++ c #{0} exiting: [{1}/{2}]", id, cons[id], fail);
                done.Signal();
            }
        static void Run(int id)
        {
            VConsole.WriteLine("+++ e/x #{0} started...", id);
            var r           = new Random((id + 1) * Environment.TickCount);
            int fail        = 0;
            int localRandom = r.Next();

            do
            {
                if ((localRandom % 100) < P)
                {
                    while ([email protected](new StCancelArgs(1)))
                    {
                        fail++;
                    }
                    localRandom = r.Next();
                    Platform.SpinWait(100);
                    @lock.Exit();
                }
                else
                {
                    localRandom = r.Next();
                }
                if ((++counts[id] % 200000) == 0)
                {
                    VConsole.Write("-{0}", id);
                }
            } while (!shutdown.IsSet);
            VConsole.WriteLine("+++ a/r #{0} exiting, after {1}[{2}] enter/exit",
                               id, counts[id], fail);
            done.Signal();
        }
Esempio n. 9
0
        //
        // The barrier action.
        //

        static void BarrierAction(object ignored)
        {
            if ((++synchs % 1000) == 0)
            {
                VConsole.Write(".");
            }
        }
            private void Run()
            {
                VConsole.WriteLine("+++ rd #{0} started...", id);
                Random r     = new Random((id + 1) * Environment.TickCount);
                int    fail  = 0;
                int    count = 0;

                do
                {
                    try {
                        while (!rwl.TryEnterRead(new StCancelArgs(r.Next(5) + 1, shutdown)))
                        {
                            fail++;
                        }
                        rwl.EnterRead();
                        Platform.SpinWait(100);
                        count++;
                        rwl.ExitRead();
                        rwl.ExitRead();
                        if ((++reads[id] % 5000) == 0)
                        {
                            VConsole.Write("-r{0}", id);
                        }
                    } catch (StThreadAlertedException) {
                        break;
                    }
                    Platform.YieldProcessor();
                } while (!shutdown.IsSet);
                VConsole.WriteLine("+++ rd #{0} exiting: [{1}/{2}]", id, count, fail);
                done.Signal();
            }
Esempio n. 11
0
            private void Run()
            {
                VConsole.WriteLine("+++ a #{0} started...", id);
                int fail = 0;

                do
                {
                    try {
                        int index = StWaitable.WaitAny(es, new StCancelArgs(1, shutdown));
                        if (index >= 0 && index < es.Length)
                        {
                            if ((++acquires[id] % 20000) == 0)
                            {
                                VConsole.Write("-{0}", id);
                            }
                        }
                        else
                        {
                            fail++;
                        }
                    } catch (StThreadAlertedException) {
                        break;
                    }
                } while (true);
                VConsole.WriteLine("+++ a #{0} exiting: [{1}/{2}]",
                                   id, acquires[id], fail);
                done.Signal();
            }
Esempio n. 12
0
            private void Run()
            {
                VConsole.WriteLine("+++ p #{0} started...", id);
                int msg   = 0;
                int fails = 0;

                do
                {
                    try {
                        if (++msg == 0)
                        {
                            msg = 1;
                        }
                        while (!queue.TryAdd(msg, new StCancelArgs(1, shutdown)))
                        {
                            fails++;
                        }
                        if ((++productions[id] % 100000) == 0)
                        {
                            VConsole.Write("-p{0}", id);
                        }
                    } catch (StThreadAlertedException) { }
                    Thread.Sleep(0);
                } while (!shutdown.IsSet);
                VConsole.WriteLine("+++ p #{0} exiting: [{1}/{2}]",
                                   id, productions[id], fails);
                done.Signal();
            }
            private void Run()
            {
                VConsole.WriteLine("+++ c #{0} started...", id);
                int fail = 0;
                int qi   = 0;
                int rmsg;

                do
                {
                    try {
                        int ws;
                        while ((ws = StBlockingQueue <int> .TryTakeAny(queues, qi, queues.Length,
                                                                       out rmsg, new StCancelArgs(1, shutdown))) == StParkStatus.Timeout)
                        {
                            fail++;
                        }
                        qi = ws;
                        if ((++consumptions[id] % 20000) == 0)
                        {
                            VConsole.Write("-c{0}", id);
                        }
                    } catch (StThreadAlertedException) {
                        while (StBlockingQueue <int> .TryTakeAny(queues, 0, queues.Length,
                                                                 out rmsg, new StCancelArgs(100)) != StParkStatus.Timeout)
                        {
                            consumptions[id]++;
                        }
                        break;
                    }
                } while (true);
                VConsole.WriteLine("+++ c #{0} exiting: [{1}/{2}]",
                                   id, consumptions[id], fail);
                done.Signal();
            }
Esempio n. 14
0
            private void Run()
            {
                int fails = 0;
                int count = 0;

                VConsole.WriteLine("+++ p #{0} started...", id);
                do
                {
                    string message = String.Format("-message {0} from producer {1} thread\n",
                                                   ++count, id);
                    try {
                        char[] chars   = message.ToCharArray();
                        int    written = queue.Write(chars, 0, chars.Length, new StCancelArgs(shutdown));
                        if (written == 0)
                        {
                            fails++;
                        }
                        else
                        {
                            productions[id] += written;
                            if ((++count % 50000) == 0)
                            {
                                VConsole.Write("-p{0}", id);
                            }
                        }
                    } catch (StThreadAlertedException) {
                        break;
                    }
                } while (!shutdown.IsSet);

                VConsole.WriteLine("+++ p #{0} exiting: [{1}/{2}]",
                                   id, productions[id], fails);
                done.Signal();
            }
            private void Run()
            {
                int fail = 0;

                VConsole.WriteLine("+++ a #{0} started...", id);
                do
                {
                    try {
                        if (sem.Acquire(1, new StCancelArgs(1, shutdown)))
                        {
                            if ((++acquires[id] % 10000) == 0)
                            {
                                VConsole.Write("-a{0}", id);
                            }
                        }
                        else
                        {
                            fail++;
                        }
                    } catch (StThreadAlertedException) {
                        break;
                    }
                } while (true);
                VConsole.WriteLine("+++ a #{0} exiting: [{1}/{2}]",
                                   id, acquires[id], fail);
                done.Signal();
            }
            private void Run()
            {
                VConsole.WriteLine("+++ p #{0} started...", id);
                int msg   = 0;
                int fails = 0;

                do
                {
                    try {
                        if (++msg == 0)
                        {
                            msg = 1;
                        }
                        // while (!queue.TryAdd(msg, new StCancelArgs(1, shutdown))) {
                        while (StBlockingQueue <int> .TryAddAny(new StBlockingQueue <int>[] { queue },
                                                                msg, new StCancelArgs(1, shutdown)) == StParkStatus.Timeout)
                        {
                            fails++;
                        }
                        if ((++productions[id] % 20000) == 0)
                        {
                            VConsole.Write("-p{0}", id);
                        }
                    } catch (StThreadAlertedException) { }
                    //Thread.Sleep(0);
                } while (!shutdown.IsSet);
                VConsole.WriteLine("+++ p #{0} exiting: [{1}/{2}]",
                                   id, productions[id], fails);
                done.Signal();
            }
 private void Run()
 {
     VConsole.WriteLine("+++ r #{0} started...", id);
     do
     {
         sem.Release(1);
         if ((++releases[id] % 10000) == 0)
         {
             VConsole.Write("-r{0}", id);
         }
         // Thread.Sleep(0);
     } while (!shutdown.IsSet);
     VConsole.WriteLine("+++ r #{0} exiting: [{1}]", id, releases[id]);
     done.Signal();
 }
Esempio n. 18
0
            private void Run()
            {
                VConsole.WriteLine("+++ e/x #{0} started...", id);
                Random r           = new Random((id + 1) * Environment.TickCount);
                int    fail        = 0;
                int    localRandom = r.Next();

                do
                {
                    if ((localRandom % 100) < P)
                    {
                        try {
                            while (!flock.WaitOne(new StCancelArgs(1, shutdown)))
                            {
                                //while (!flock.WaitOne(new StCancelArgs(1, shutdown))) {
                                //while (StWaitable.WaitAny(new StWaitable[] { flock },
                                //                    new StCancelArgs(1, shutdown)) != StParkStatus.Success) {
                                //while (!StWaitable.WaitAll(new StWaitable[] { flock },
                                //                           new StCancelArgs(1, shutdown))) {

                                fail++;
                            }
                            for (int i = 1; i < REENTER; i++)
                            {
                                flock.WaitOne();
                            }
                            localRandom = sharedRandom = r.Next();
                            for (int i = 0; i < REENTER; i++)
                            {
                                flock.Exit();
                            }
                        } catch (StThreadAlertedException) {
                            break;
                        }
                    }
                    else
                    {
                        localRandom = r.Next();
                    }
                    if ((++counts[id] % 20000) == 0)
                    {
                        VConsole.Write("-{0}", id);
                    }
                } while (!shutdown.IsSet);
                VConsole.WriteLine("+++ e/x #{0} exiting: [{1}/{2}]",
                                   id, counts[id], fail);
                done.Signal();
            }
        private static void Run(int id)
        {
            int fail   = 0;
            var sem0   = new StSemaphore(0);
            var sem1   = new StSemaphore(0);
            var sem2   = new Semaphore(0, int.MaxValue);
            var sem3   = new Semaphore(0, int.MaxValue);
            var stsems = new[] { sem0, sem1 };
            var whsems = new[] { sem2, sem3 };

            VConsole.WriteLine("+++ w #{0} started...", id);
            do
            {
                ThreadPool.QueueUserWorkItem(delegate {
                    sem0.Release(1);
                    sem1.Release(1);
                    Thread.Sleep(0);
                    sem2.Release(1);
                    sem3.Release(1);
                    if (sem1.Wait(1, new StCancelArgs(0)))
                    {
                        Thread.Sleep(0);
                        sem1.Release(1);
                    }
                });

                try {
                    do
                    {
                        if (StWaitable.WaitAll(stsems, whsems, new StCancelArgs(id)))
                        {
                            break;
                        }
                        fail++;
                    } while (true);
                } catch (StThreadAlertedException) {
                    break;
                }

                if ((++counts[id] % 1000) == 0)
                {
                    VConsole.Write("-{0}", id);
                }
            } while (shutdown == 0);
            VConsole.WriteLine("+++ w #{0} exiting: [{1}/{2}]", id, counts[id], fail);
            done.Signal();
        }
            private void Run()
            {
                VConsole.WriteLine("+++ p #{0} started...", id);
                String data = "data";

                do
                {
                    try {
                        q.Offer(data, new StCancelArgs(shutdown));
                        if ((++prods[id] % 10000) == 0)
                        {
                            VConsole.Write("-p{0}", id);
                        }
                    } catch (StThreadAlertedException) { }
                } while (!shutdown.IsSet);
                VConsole.WriteLine("+++ p #{0} exiting: [{1}]", id, prods[id]);
                done.Signal();
            }
Esempio n. 21
0
            private void Run()
            {
                VConsole.WriteLine("+++ e/x #{0} started...", id);
                Random r           = new Random((id + 1) * Environment.TickCount);
                int    fail        = 0;
                int    localRandom = r.Next();

                do
                {
                    if ((localRandom % 100) < P)
                    {
                        while (!Monitor.TryEnter(_clrLock))
                        {
                            fail++;
                            Thread.Sleep(10);
                        }
                        for (int i = 1; i < REENTER; i++)
                        {
                            Monitor.Enter(_clrLock);
                        }
                        localRandom = sharedRandom = r.Next();
                        Platform.SpinWait(100);
                        for (int i = 1; i < REENTER; i++)
                        {
                            Monitor.Exit(_clrLock);
                        }
                        Monitor.Exit(_clrLock);
                    }
                    else
                    {
                        localRandom = r.Next();
                    }
                    if ((++counts[id] % 50000) == 0)
                    {
                        VConsole.Write("-{0}", id);
                    }
                } while (!shutdown.IsSet);
                VConsole.WriteLine("+++ a/r #{0} exiting, after {1}[{2}] enter/exit",
                                   id, counts[id], fail);
                done.Signal();
            }
Esempio n. 22
0
        public static void Run <T>(int timeout)
        {
            Thread.CurrentThread.Priority = ThreadPriority.Highest;
            Action stop = (Action)typeof(T).GetMethod("Run").Invoke(null, new object[0]);

            if (timeout == Timeout.Infinite)
            {
                VConsole.WriteLine("+++ press any key to terminate...");
                Console.ReadLine();
            }
            else
            {
                Thread.Sleep(timeout);
            }

            VConsole.WriteLine("+++ stopping...");
            stop();

            VConsole.Write("+++ press any key to exit...");
            Console.ReadLine();
        }
            private void Run()
            {
                VConsole.WriteLine("+++ p #{0} started...", id);
                int    msg = 0;
                Random r   = new Random(id);

                do
                {
                    try {
                        queues[r.Next(QUEUES)].TryAdd(msg, new StCancelArgs(shutdown));
                        if ((++productions[id] % 20000) == 0)
                        {
                            VConsole.Write("-p{0}", id);
                        }
                        msg++;
                    } catch (StThreadAlertedException) {
                        break;
                    }
                } while (!shutdown.IsSet);
                VConsole.WriteLine("+++ p #{0} exiting: [{1}]", id, productions[id]);
                done.Signal();
            }
Esempio n. 24
0
            private void Run()
            {
                int fails = 0;

                char[] buffer = new char[16];
                int    read;
                int    count = 0;

                VConsole.WriteLine("+++ c #{0} started...", id);
                do
                {
                    try {
                        read = queue.Read(buffer, 0, buffer.Length,
                                          new StCancelArgs(1, shutdown));
                        if (read == 0)
                        {
                            fails++;
                        }
                        else
                        {
                            consumptions[id] += read;
                            if ((++count % 50000) == 0)
                            {
                                VConsole.Write("-c{0}", id);
                            }
                        }
                    } catch (StThreadAlertedException) {
                        while ((read = queue.Read(buffer, 0, buffer.Length,
                                                  new StCancelArgs(1))) != 0)
                        {
                            consumptions[id] += read;
                        }
                        break;
                    }
                } while (true);
                VConsole.WriteLine("+++ c #{0} exiting : [{1}/{2}]",
                                   id, consumptions[id], fails);
                done.Signal();
            }
Esempio n. 25
0
            private void Run()
            {
                VConsole.WriteLine("+++ wr #{0} started...", id);
                Random r    = new Random((id + 1) * Environment.TickCount);
                int    fail = 0;

                do
                {
                    try {
                        if (rwl.TryEnterWrite(new StCancelArgs(r.Next(10) + 1, shutdown)))
                        {
                            if ((++writes[id] % 20000) == 0)
                            {
                                VConsole.Write("-w{0}", id);
                            }
                            for (int i = 1; i < REENTER; i++)
                            {
                                rwl.EnterWrite();
                            }
                            for (int i = 0; i < REENTER; i++)
                            {
                                rwl.ExitWrite();
                            }
                        }
                        else
                        {
                            fail++;
                        }
                        //Thread.Sleep(r.Next(1, 10));
                    } catch (StThreadAlertedException) {
                        break;
                    }
                } while (!shutdown.IsSet);
                VConsole.WriteLine("+++ wr #{0} exiting: [{1}/{2}]", id, writes[id], fail);
                done.Signal();
            }