public static Action Run() {
			for (int i = 0; i < RING_THREADS; i++) {
                int id = i;
			    evts[id] = new StNotificationEvent();
                new Thread(_ => RingThread(id)) { Name = "r #" + id }.Start();
			}

            for (int i = 0; i < GLOBAL_THREADS; i++) {
                int id = i;
                new Thread(_ => GlobalThread(id, (id & 1) == 0)) { Name = "g #" + id }.Start();
			}

		    start.WaitOne();
		    evts[0].Set();

            Action stop = () => {
                shutdown.Set();
                done.WaitOne();
                long t = 0;
                for (int i = 0; i <RING_THREADS; i++) {
                    t += counts[i];
                }

                VConsole.WriteLine("+++ Total: {0}", t);
            };
            return stop;
		}
Exemple #2
0
		public ManualResetEventSlim (bool initialState, int spinCount)
		{
			if (spinCount < 0) {
				throw new ArgumentOutOfRangeException ("spinCount is less than 0", "spinCount");
			}

			evt = new StNotificationEvent (initialState, spinCount);
		}
        //
        // Starts the test.
        //

        internal static Action Run() {

            Thread.CurrentThread.Priority = ThreadPriority.Highest;
            StSemaphore s = new StSemaphore(0);
            StNotificationEvent doUnreg = new StNotificationEvent();
        	StRegisteredWait regWait = s.RegisterWait(RegisteredWaitCallback, null, 250, false);
            new UnregisterThread(regWait, doUnreg).Start();
	        s.Release(20);
            return () => {
	            doUnreg.Set();
	            for (int i = 0; i < 100; i++) {
		            s.Release(1);
	            }
	            Console.ReadLine();
            };
        }
Exemple #4
0
        //
        // Starts the test.
        //

        internal static Action Run()
        {
            Thread.CurrentThread.Priority = ThreadPriority.Highest;
            StSemaphore         s       = new StSemaphore(0);
            StNotificationEvent doUnreg = new StNotificationEvent();
            StRegisteredWait    regWait = s.RegisterWait(RegisteredWaitCallback, null, 250, false);

            new UnregisterThread(regWait, doUnreg).Start();
            s.Release(20);
            return(() => {
                doUnreg.Set();
                for (int i = 0; i < 100; i++)
                {
                    s.Release(1);
                }
                Console.ReadLine();
            });
        }
        public static Action Run()
        {
            for (int i = 0; i < RING_THREADS; i++)
            {
                int id = i;
                evts[id] = new StNotificationEvent();
                new Thread(_ => RingThread(id))
                {
                    Name = "r #" + id
                }.Start();
            }

            for (int i = 0; i < GLOBAL_THREADS; i++)
            {
                int id = i;
                new Thread(_ => GlobalThread(id, (id & 1) == 0))
                {
                    Name = "g #" + id
                }.Start();
            }

            start.WaitOne();
            evts[0].Set();

            Action stop = () => {
                shutdown.Set();
                done.WaitOne();
                long t = 0;
                for (int i = 0; i < RING_THREADS; i++)
                {
                    t += counts[i];
                }

                VConsole.WriteLine("+++ Total: {0}", t);
            };

            return(stop);
        }
Exemple #6
0
 public UnregisterThread(StRegisteredWait regWait, StNotificationEvent doUnreg)
 {
     this.regWait = regWait;
     this.doUnreg = doUnreg;
 }
	        public UnregisterThread(StRegisteredWait regWait, StNotificationEvent doUnreg) {
                this.regWait = regWait;
                this.doUnreg = doUnreg;
            }