Beispiel #1
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();
            }
Beispiel #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();
            }
        public static void GlobalThread(int id, bool waitAll)
        {
            int fail  = 0;
            int count = 0;

            try {
                do
                {
                    if (waitAll ? StWaitable.WaitAll(evts, new StCancelArgs(shutdown))
                                : StWaitable.WaitAny(evts, new StCancelArgs(id, shutdown)) != StParkStatus.Timeout)
                    {
                        count++;
                    }
                    else
                    {
                        fail++;
                    }
                } while (!shutdown.IsSet);
            }
            catch (StThreadAlertedException) { }

            VConsole.WriteLine("+++ {0} (Wait{1}) exiting: {2}/{3}",
                               Thread.CurrentThread.Name, waitAll ? "All" : "Any", count, fail);
            done.Signal();
        }