Beispiel #1
0
        public void TestCurrentContextClone()
        {
            ManualResetEvent resetEvent = new ManualResetEvent(false);

            resetEvent.Reset();
            if (Fork.CloneThread())
            {
                resetEvent.Set();
            }
            else
            {
                resetEvent.WaitOne();
                resetEvent.Dispose();
            }
        }
Beispiel #2
0
        public void TestCurrentContextCloneInsideAnother()
        {
            CountdownEvent countdownEvent = new CountdownEvent(2);

            countdownEvent.Reset(2);

            if (Fork.CloneThread())
            {
                Fork.CloneThread();
                countdownEvent.Signal();
            }
            else
            {
                countdownEvent.Wait();
                countdownEvent.Dispose();
            }
        }
Beispiel #3
0
        static void MakeFork()
        {
            //var cdevent = new CountdownEvent(2);
            var sameLocalVariable = 123;
            var stopwatch         = Stopwatch.StartNew();

            // Splitting current thread flow to two threads
            var forked = Fork.CloneThread();

            lock (Sync)
            {
                Console.WriteLine("in {0} thread: {1}, local value: {2}, time to enter = {3} ms",
                                  forked ? "forked" : "parent",
                                  Thread.CurrentThread.ManagedThreadId,
                                  sameLocalVariable,
                                  stopwatch.ElapsedMilliseconds);
            }

            // Here forked thread's life will be stopped
        }
Beispiel #4
0
        public void TestCurrentContextShouldBeSavedForValueTypes()
        {
            ManualResetEvent resetEvent = new ManualResetEvent(false);

            resetEvent.Reset();
            int data = 123;

            var forked = Fork.CloneThread();

            if (data != 123)
            {
                throw new Exception("data was not saved");
            }

            if (forked)
            {
                resetEvent.Set();
            }
            else
            {
                resetEvent.WaitOne();
                resetEvent.Dispose();
            }
        }