public void SimpleAtomicityTest2()
        {
            racyvariable = 0;

            Thread t = new Thread((Object irrelevant) =>
            {
                ChessAPI.TraceEvent("doing child ops");
                ChessAPI.PreemptionDisable();
                ChessAPI.PreemptionDisable();
                ChessAPI.PreemptionEnable();
                ChessAPI.PreemptionEnable();
                racyvariable++;
            });

            t.Start();

            ChessAPI.TraceEvent("doing parent ops");
            ChessAPI.PreemptionDisable();
            racyvariable++;
            ChessAPI.PreemptionEnable();

            t.Join();

            Assert.AreEqual(2, racyvariable);
        }
        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();
            }
        }