using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
namespace 线程进程学习
{
class Program
{
static void Main(string[] args)
{
var one = new object();
var two = new object();
new Task(new test(one, two).lock1).Start();
new Task(new test(one, two).lock2).Start();
Console.ReadKey();
}
public class test
{
public test(object temp1, object temp2)
{
this.temp1 = temp1;
this.temp2 = temp2;
}
public object temp1;
public object temp2;
public static int temp3 = 1;
public void lock1()
{
while (true)
{
lock (temp1)
{
lock (temp2)
{
temp3++;
Console.WriteLine(temp3);
}
}
}
}
public void lock2()
{
while (true)
{
lock (temp2)
{
lock (temp1)
{
temp3++;
Console.WriteLine(temp3);
}
}
}
}
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
namespace 线程进程学习
{
class Program
{
static void Main(string[] args)
{
var one = new object();
var two = new object();
new Task(new test(one, two).lock1).Start();
new Task(new test(one, two).lock2).Start();
Console.ReadKey();
}
public class test
{
public test(object temp1, object temp2)
{
this.temp1 = temp1;
this.temp2 = temp2;
}
public object temp1;
public object temp2;
public static int temp3 = 1;
public void lock1()
{
while (true)
{
lock (temp1)
{
lock (temp2)
{
temp3++;
Console.WriteLine(temp3);
}
}
}
}
public void lock2()
{
while (true)
{
lock (temp2)
{
lock (temp1)
{
temp3++;
Console.WriteLine(temp3);
}
}
}
}
}
}
}