using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using System.Threading;

namespace BarrierDemo
{
    class Program
    {
        const int ileWatkow = 10;
        static Barrier b = new Barrier(ileWatkow, (Barrier _b) => { Console.WriteLine(); });

        static void Main(string[] args)
        {
            ThreadStart metodaWatku = 
                () => 
                {
                    for (int i = 0; i < 10; ++i)
                    {
                        Console.Write(i.ToString());
                        b.SignalAndWait();
                    }
                };
            Thread[] watki = new Thread[ileWatkow];            
            for (int i = 0; i < ileWatkow; ++i) 
            {
                watki[i] = new Thread(metodaWatku);
                watki[i].Start();
            }

            Console.ReadLine();
        }
    }
}
