internal void Work() { if (threadStart != null) { threadStart(initializationInformation); } threadStart = null; initializationInformation = null; while (true) { //When ThreadManager sees a loop available, it set it up and then wake me up. getToWork.WaitOne(); if (manager.currentLoopBody == null) { //Woops, looks like it's time for me to die. manager.OnWorkerFinish(); return; } while (manager.jobIndex <= manager.maxJobIndex) { //Claim a piece of job. int jobIndex = Interlocked.Increment(ref manager.jobIndex); //The job interval. int endIndex = jobIndex * iterationsPerSteal; int beginIndex = endIndex - iterationsPerSteal; //Do the job piece. Make sure you don't do more than exists in the list itself. for (int i = beginIndex; i < endIndex && i < finalIndex; i++) { manager.currentLoopBody(i); } } //this is not 'thread safe' but the result of the unsafety is a quick fail in the worst case. manager.OnWorkerFinish(); } }