private static void ForkJoin(T objundertest, string[][] matrix, Action <T>[][] ops) { Thread[] threads = new Thread[ops.Length]; // Create all threads for (int t = 0; t < threads.Length; t++) { int tt = t; threads[t] = new Thread(() => { for (int o = 0; o < ops[tt].Length; o++) { try { ChessAPI.TraceEvent(matrix[tt][o]); ChessAPI.ObserveOperationCall(matrix[tt][o]); ops[tt][o](objundertest); } catch (Exception e) { if (ChessAPI.IsBreakingDeadlock()) { break; } ChessAPI.ObserveString("exception", e.Message); } ChessAPI.ObserveOperationReturn(); } }); } // start all threads foreach (var t in threads) { t.Start(); } // join all threads foreach (var t in threads) { t.Join(); } }
public void SmallPassingSample1() { a = 0; b = 0; System.Threading.Tasks.Parallel.Invoke( () => { ChessAPI.ObserveOperationCall("first"); a = 1; a = 1; b = a; ChessAPI.ObserveInteger("val", 2); ChessAPI.ObserveOperationReturn(); }, () => { ChessAPI.ObserveOperationCall("second"); b = 1; ChessAPI.ObserveString("ret", "hurra"); b = 1; ChessAPI.ObserveOperationReturn(); } ); }