码迷,mamicode.com
首页 > 编程语言 > 详细

多线程14-Barrier

时间:2016-06-22 15:47:55      阅读:230      评论:0      收藏:0      [点我收藏+]

标签:

class Program
    {
        static Barrier barrier = new Barrier(2, b => Console.WriteLine("End of phase {0}", b.CurrentPhaseNumber + 1));
        static void PalyMusic(string name, string message, int second)
        {
            for (var i = 1; i <= 3; i++)
            {
                Console.WriteLine("----------------------------------");
                Thread.Sleep(TimeSpan.FromSeconds(second));
                Console.WriteLine("{0} Start to {1}", name, message);
                Thread.Sleep(TimeSpan.FromSeconds(second));
                Console.WriteLine("{0} finisheds to {1}", name, message);
                barrier.SignalAndWait();
            }
        }
        static void Main()
        {
            var t1 = new Thread(() => PalyMusic("the guitarist", "paly an amzaing solo", 5));
            var t2 = new Thread(() => PalyMusic("the singer", "sing his song", 2));
            t1.Start();
            t2.Start();
        }
    }

多线程14-Barrier

标签:

原文地址:http://www.cnblogs.com/shidengyun/p/5607034.html

踩
(0)
赞
(0)
   
举报
评论 一句话评论(0)
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!