Esempio n. 1
0
        /// <summary>
        /// For loop with exception-catch-and-propagate.
        /// </summary>
        /// <param name="loopBegin"></param>
        /// <param name="loopEnd"></param>
        /// <param name="proc"></param>
        public static void StartLoopsException(int loopBegin, int loopEnd, LoopProc2 proc)
        {
            Exception threadException = null;

            StartThreads(
                delegate(object arg) {
                ThreadInfo threadInfo = arg as ThreadInfo;
                LoopInterval loop     = threadInfo.GetLoopInterval(loopEnd - loopBegin);
                try {
                    for (int n = loop.Begin; n < loop.End; n++)
                    {
                        proc(loopBegin + n, threadInfo.ThreadIndex);
                    }
                } catch (Exception ex) {
                    threadException = ex;
                }
                threadInfo.Finished();
            }
                );

            if (threadException != null)
            {
                throw threadException;
            }
        }
Esempio n. 2
0
 public static ThreadInfo[] StartThreads(int N, ThreadProc2 proc)
 {
     return(StartThreads(delegate(object arg) {
         ThreadInfo tInfo = arg as ThreadInfo;
         LoopInterval loopInfo = tInfo.GetLoopInterval(N);
         proc(loopInfo.Begin, loopInfo.End);
         tInfo.Finished();
     }));
 }
Esempio n. 3
0
 // Loop with thread initialization section.
 // Usage: Replaces for(int n=s; n<t; n++) ..." by
 //   MultiThreading.StartLoops(s, t, delegate(int loopBegin, int loopEnd) {
 //     <Thrad Initialization Code>
 //     for(int n=loopBegin; n<loopEnd; n++) {
 //       ...
 //     }
 //     <Thread Dispose Code>
 //   }
 //
 public static void StartLoops(int loopBegin, int loopEnd, LoopProc3 proc)
 {
     StartThreads(
         delegate(object arg) {
         ThreadInfo threadInfo = arg as ThreadInfo;
         LoopInterval loop     = threadInfo.GetLoopInterval(loopEnd - loopBegin);
         proc(loopBegin + loop.Begin, loopBegin + loop.End);
         threadInfo.Finished();
     }
         );
 }
Esempio n. 4
0
 public static ThreadInfo[] StartLoops(int loopBegin, int loopEnd, LoopProc4 proc)
 {
     return(StartThreads(
                delegate(object arg) {
         ThreadInfo threadInfo = arg as ThreadInfo;
         LoopInterval loop = threadInfo.GetLoopInterval(loopEnd - loopBegin);
         for (int n = loop.Begin; n < loop.End; n++)
         {
             proc(loopBegin + n, threadInfo);
         }
         threadInfo.Finished();
     }
                ));
 }