Exemplo n.º 1
0
 static FalseSharing()
 {
     for (int i = 0; i < Ints.Length; i++)
     {
         Ints[i] = new VolatileInt();
     }
 }
Exemplo n.º 2
0
        public void TestEnumerator()
        {
            var queue   = new SharedQueue();
            var c1      = new VolatileInt();
            var c2      = new VolatileInt();
            var thread1 = new Thread(() => { foreach (int v in queue)
                                             {
                                                 c1.v += v;
                                             }
                                     });
            var thread2 = new Thread(() => { foreach (int v in queue)
                                             {
                                                 c2.v += v;
                                             }
                                     });

            thread1.Start();
            thread2.Start();
            queue.Enqueue(1);
            queue.Enqueue(2);
            queue.Enqueue(3);
            queue.Close();
            thread1.Join();
            thread2.Join();
            Assert.AreEqual(6, c1.v + c2.v);
        }
        public void TestEnumerator()
        {
            SharedQueue q  = new SharedQueue();
            VolatileInt c1 = new VolatileInt();
            VolatileInt c2 = new VolatileInt();
            Thread      t1 = new Thread(delegate() {
                foreach (int v in q)
                {
                    c1.v += v;
                }
            });
            Thread t2 = new Thread(delegate() {
                foreach (int v in q)
                {
                    c2.v += v;
                }
            });

            t1.Start();
            t2.Start();
            q.Enqueue(1);
            q.Enqueue(2);
            q.Enqueue(3);
            q.Close();
            t1.Join();
            t2.Join();
            Assert.AreEqual(6, c1.v + c2.v);
        }
 public void TestEnumerator()
 {
     SharedQueue q = new SharedQueue();
     VolatileInt c1 = new VolatileInt();
     VolatileInt c2 = new VolatileInt();
     Thread t1 = new Thread(delegate() {
             foreach (int v in q) c1.v+=v;
         });
     Thread t2 = new Thread(delegate() {
             foreach (int v in q) c2.v+=v;
         });
     t1.Start();
     t2.Start();
     q.Enqueue(1);
     q.Enqueue(2);
     q.Enqueue(3);
     q.Close();
     t1.Join();
     t2.Join();
     Assert.AreEqual(6, c1.v + c2.v);
 }
Exemplo n.º 5
0
        public ThreadReceivingPlayerStats(int num_thread, VolatileInt[] thread_flags, Socket handle)
        {
            this.thread_num = num_thread;
            this.thread_flags = thread_flags;
            this.handle = handle;

            thread = new Thread(ConnectionHandler);
            thread.IsBackground = true;
            thread.Start();
        }
 public void TestEnumerator()
 {
     var queue = new SharedQueue();
     var c1 = new VolatileInt();
     var c2 = new VolatileInt();
     var thread1 = new Thread(() => { foreach (int v in queue) c1.v += v; });
     var thread2 = new Thread(() => { foreach (int v in queue) c2.v += v; });
     thread1.Start();
     thread2.Start();
     queue.Enqueue(1);
     queue.Enqueue(2);
     queue.Enqueue(3);
     queue.Close();
     thread1.Join();
     thread2.Join();
     Assert.AreEqual(6, c1.v + c2.v);
 }