这个只是一个并发操作,还未实现真正的同步,如同在经过同一个地点时,一个是从高架上走的,一个是从路面走的
using System;
using System.Collections.Generic;using System.Linq;
using System.Text;
using System.Threading;
namespace ThreadSynchronization
{
class Program
{
static Thread t1 = new Thread(write1);
static Thread t2 = new Thread(write2);
static List<int> list = new List<int>();
private static void write1()
{
Monitor.Enter(list); //使用Monitor时,最后要手动释放list
try
{
//lock (list) //lock在执行完后会自动释放掉
//{
for (int i = 0; i < 10; i++)
{