string a="abc";lock(a){....};在實際使用中我發現鎖定的不是a對象,而是以a對象作為標識的{}內的代碼塊.. 但發現資料上是像圖中那樣說的,是我沒理解正確呢還是資料錯誤?請高手解惑.using System;using System.Threading;class Program
{
static void Main(string[] args)
{
Student s = new Student { Name="yh"};
Thread t=new Thread (new ThreadStart(()=>{lock (s) { Thread.Sleep(100000); }}));
t.Start();
Thread.Sleep(1000);
Console.WriteLine(s.Name);//這里沒有等鎖的線程結束才執行..所以我覺得資料說的不對..你們認為呢?
Console.ReadKey();
}
}internal class Student
{ public string Name { get; set; }
- 1 回答
- 0 關注
- 849 瀏覽
添加回答
舉報
0/150
提交
取消