using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading;
namespace ConsoleApplication2 { public class MutexControl { private const int THREAD_NUM = 50; //一共需要运行的线程数 private const int MAX_RUNTHREAD = 6; //可同时执行的最大线程数 //private AutoResetEvent[] event = null;
//这个变量仅为了测试当前运行的线程数 private static int testThreadNum = 0;
private Mutex[] muxConsole = null;
public MutexControl() { muxConsole = new Mutex[MAX_RUNTHREAD]; for (int i = 0; i < MAX_RUNTHREAD; i++) { muxConsole[i] = new Mutex(); //event[i] = new AutoResetEvent(false); } }
public void ApplySync() { //创建指定数量的线程 //是线程调用Run方法 //启动线程 for (int i = 0; i < THREAD_NUM; i++) { Thread trd = new Thread(new ParameterizedThreadStart(DoWork));