static void Main() { Kerfuffle kerf = new Kerfuffle(); const int NUM_THREADS = 8; Thread[] threads = new Thread[NUM_THREADS]; TestThread[] testThreads = new TestThread[NUM_THREADS]; // invoke the threads for (int i = 0; i < NUM_THREADS; i++) { testThreads[i] = new TestThread(kerf, i); threads[i] = new Thread(new ThreadStart(testThreads[i].Run)); threads[i].Start(); } // wait for the threads to finish for (int i = 0; i < NUM_THREADS; i++) { threads[i].Join(); } for (int i = 0; i < NUM_THREADS; i++) { if (testThreads[i].Failed) { throw new Exception("Test Failed"); } } }
static void Main() { Kerfuffle kerf = new Kerfuffle(); const int NUM_THREADS = 8; Thread[] threads = new Thread[NUM_THREADS]; TestThread[] testThreads = new TestThread[NUM_THREADS]; // invoke the threads for (int i=0; i<NUM_THREADS; i++) { testThreads[i] = new TestThread(kerf, i); threads[i] = new Thread(new ThreadStart(testThreads[i].Run)); threads[i].Start(); } // wait for the threads to finish for (int i=0; i<NUM_THREADS; i++) { threads[i].Join(); } for (int i=0; i<NUM_THREADS; i++) { if (testThreads[i].Failed) throw new Exception("Test Failed"); } }
public TestThread(Kerfuffle t, int id) { kerf = t; threadId = id; }