Exemplo n.º 1
0
        public void TwoThreads()
        {
            var sut    = new SimpleBarrier(2);
            var result = new ConcurrentQueue <string>();

            var worker1 = new Thread(DoWork);

            worker1.Start();

            var worker2 = new Thread(DoWork);

            worker2.Start();

            worker1.Join();
            worker2.Join();

            void DoWork()
            {
                for (var i = 0; i < 10; i++)
                {
                    var item = "STAGE:" + i;
                    result.Enqueue(item);
                    sut.Wait();
                }
            }

            while (result.Any())
            {
                result.TryDequeue(out var worker1Item);
                result.TryDequeue(out var worker2Item);

                Assert.Equal(worker1Item, worker2Item);
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GBlock"/> class.
 /// </summary>
 /// <param name="grid">The parent grid.</param>
 /// <param name="size">The size.</param>
 /// <param name="x">The x value.</param>
 /// <param name="y">The y value.</param>
 public GBlock(GGrid grid, dim3 size, int x, int y)
 {
     Idx         = new dim3(x, y);
     Dim         = size;
     Barrier     = new SimpleBarrier(size.x * size.y * size.z);
     WarpBarrier = new SimpleWarpBarrier((int)Math.Ceiling((size.x * size.y * size.z) / 32.0f), 32);
     Grid        = grid;
     _shared     = new Dictionary <string, object>();
     _lock       = new object();
 }
Exemplo n.º 3
0
        public void OneThread()
        {
            var sut = new SimpleBarrier(1);

            var worker = new Thread(DoWork);

            worker.Start();
            worker.Join();

            void DoWork()
            {
                for (var i = 0; i < 1000; i++)
                {
                    sut.Wait();
                }
            }
        }