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)
        {
            Action<object> metodaWatku =
                (object parametr) =>
                {
                    for (int i = 0; i < 10; ++i)
                    {
                        Console.Write(i.ToString());
                        b.SignalAndWait();
                    }
                };
            for (int i = 0; i < ileWatkow; ++i)
                ThreadPool.QueueUserWorkItem(new WaitCallback(metodaWatku));

            Console.ReadLine();
        }
    }
}
