Пример #1
0
        public void Sample2()
        {
            Pair   p  = new Pair();
            Thread t1 = new Thread(() =>
            {
                ChessAPI.ObserveOperationCall("set a=0");
                p.Write_a(0);
                ChessAPI.ObserveOperationReturn();
                ChessAPI.ObserveOperationCall("read both");
                ChessAPI.ObserveInteger("val", p.Read_both());
                ChessAPI.ObserveOperationReturn();
                ChessAPI.ObserveOperationCall("read a");
                ChessAPI.ObserveInteger("val", p.Read_a());
                ChessAPI.ObserveOperationReturn();
            });
            Thread t2 = new Thread(() =>
            {
                ChessAPI.ObserveOperationCall("set b=10");
                p.Write_b(10);
                ChessAPI.ObserveOperationReturn();
                ChessAPI.ObserveOperationCall("read both");
                ChessAPI.ObserveInteger("val", p.Read_both());
                ChessAPI.ObserveOperationReturn();
            });

            t1.Start();
            t2.Start();
            t1.Join();
            t2.Join();
        }
Пример #2
0
        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();
            }
        }
Пример #3
0
 public void SmallFailingSample1()
 {
     a = 0;
     b = 0;
     System.Threading.Tasks.Parallel.Invoke(
         () =>
     {
         ChessAPI.ObserveOperationCall("first");
         a = 1;
         ChessAPI.ObserveInteger("val", a);
         ChessAPI.ObserveOperationReturn();
     },
         () =>
     {
         ChessAPI.ObserveOperationCall("second");
         a = 2;
         ChessAPI.ObserveOperationReturn();
     }
         );
 }
Пример #4
0
 [ExpectedResult(TestResultType.Error)]   // TODO make special error type for these?
 public void Test1()
 {
     System.Threading.Tasks.Parallel.Invoke(
         () =>
     {
         ChessAPI.ObserveOperationCall("first");
         a = 1;
         a = 1;
         b = a;
         ChessAPI.ObserveOperationReturn();
     },
         () =>
     {
         ChessAPI.ObserveOperationCall("second");
         b = 1;
         b = 1;
         ChessAPI.ObserveOperationReturn();
     }
         );
 }
Пример #5
0
 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();
     }
         );
 }