标签:idt 并发 测试 new 有趣的 ros ges div code
给一个很有趣的进程并发性的小例子:
static void Main(string[] args) { new Thread(WriteX).Start(); new Thread(WriteY ).Start(); WriteZ(); Console.ReadKey(); } static void WriteX() { Console.WriteLine($"线程编号X:{Thread.CurrentThread.ManagedThreadId}"); for (int i = 0; i < 1000; i++) Console.Write("x"); } static void WriteY() { Console.WriteLine($"线程编号Y:{Thread.CurrentThread.ManagedThreadId}"); for (int i = 0; i < 1000; i++) Console.Write("y"); } static void WriteZ() { Console.WriteLine($"线程编号Z:{Thread.CurrentThread.ManagedThreadId}"); for (int i = 0; i < 1000; i++) Console.Write("z"); } }
一共开了三个进程,分别打印X, Y,Z,看运行结果(每次都是随机的)
标签:idt 并发 测试 new 有趣的 ros ges div code
原文地址:http://www.cnblogs.com/xiao9426926/p/5983406.html