多线程同步问题 LOCK
初次接触多程序同步, 很是头疼, 望各位前辈帮帮小弟, 先谢了
namespace ThreadDemo{ public partial class Form1 : Form { private Yan y = new Yan(); public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { Thread t1 = new Thread(T1); t1.Name = "t1"; Thread t2 = new Thread(T2); t2.Name = "t2"; t1.Start(); t2.Start(); } private void T1() { lock (y) { for (int i = 0; i < 10000000; ++i) ; y.str = "先"; MessageBox.Show(y.str); } } private void T2() { y.str = "后"; MessageBox.Show(y.str); } } public class Yan { public string str = ""; }}