public void Run() { Thread currentThread = Thread.CurrentThread; String oldName = currentThread.Name; if (runnable is INamedRunnable) { currentThread.Name = ((INamedRunnable)runnable).Name; } try { try { if (forkState != null) { forkState.Use(runnable); } else { runnable.Run(); } } catch (Exception e) { throwableHolder.Value = e; } finally { threadLocalCleanupController.CleanupThreadLocal(); latch.CountDown(); } } finally { currentThread.Name = oldName; } }
public void Run() { try { Thread currentThread = Thread.CurrentThread; String oldName = currentThread.Name; if (buildThreadLocals) { String name = runnableHandle.createdThread.Name; currentThread.Name = name + " " + oldName; } try { Object parallelLock = runnableHandle.parallelLock; IList <V> items = runnableHandle.items; IForkState forkState = runnableHandle.forkState; ParamHolder <Exception> exHolder = runnableHandle.exHolder; CountDownLatch latch = runnableHandle.latch; while (true) { V item; lock (parallelLock) { if (exHolder.Value != null) { // an uncatched error occurred somewhere return; } // pop the last item of the queue item = items[items.Count - 1]; items.RemoveAt(items.Count - 1); } if (item == null) { // queue finished return; } try { if (buildThreadLocals) { forkState.Use(runnableHandle.run, item); } else { runnableHandle.run(item); } } catch (Exception e) { lock (parallelLock) { if (exHolder.Value == null) { exHolder.Value = e; } } } finally { latch.CountDown(); } } } finally { if (buildThreadLocals) { currentThread.Name = oldName; } } } finally { if (buildThreadLocals) { runnableHandle.threadLocalCleanupController.CleanupThreadLocal(); } } }