考考你,一个很简单却很多人都不确定的问题

A:

void Test(int i)

{

    while(i>0)

  {

      lock(this)

      {

          i--;

          Test(i);

      } 

  }

}

 

会死锁不?

或者,B:

void Test(int i)

{

    while(i>0)

  {

      lock(this)

      {

          i--;

    
                    System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(delegate(object obj)
                    {
                        int ii=(int)obj;

               Test(ii);

                    }));

       thread.Start(i);

      } 

  }

}

会死锁不?

再或者,C:

void Test(int i)

{

    while(i>0)

  {

      lock(this)

      {

          i--;

    lock(this.GetType())

    {
                    System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(delegate(object obj)
                    {
                        int ii=(int)obj;

               Test(ii);

                    }));

       thread.Start(i);

    }

      } 

  }

}

会死锁不?

posted on 2011-09-26 19:22  狼行虹雨  阅读(2088)  评论(12)    收藏  举报

导航