Another deadlock in 4.2.7.0 with GC

If I call Debug.GC(true) the code freeze.

It’s one of those hard freezes that the debuger cant resolve.

The problem seams to happen when there is a WaitHandler some where in the program that is in WaitOne state, If there is a WaitOne in a thread a different thread will get this problem.

I wrote a test code to illustrate where it freezes.


using System;
using Microsoft.SPOT;
using System.Threading;
using System.Collections;

namespace racedisplay.NETMF.Test
{
    public class Program
    {
        public static void Main()
        {
            Debug.GC(false);    // OK
            Threadout threadout1 = new Threadout();
            Debug.GC(false);    // NOT OK, freeze
            Threadout threadout2 = new Threadout();
            Thread.Sleep(1000);
            Timeout timeout = new Timeout();
        }
    }

    public class Signal
    {
        private ManualResetEvent signal;
        private Object locker = new Object();

        public Signal()
        {
            signal = new ManualResetEvent(false);
            Thread setter = new Thread(new ThreadStart(Worker));
            setter.Start();
        }

        public void Wait(int id)
        {
            lock (locker)
            {
                Debug.Print("Wait for " + id.ToString());
                signal.WaitOne();
                signal.Reset();
                Debug.Print("Done for " + id.ToString());
            }
        }

        private void Worker()
        {
            while (true)
            {
                //signal.Set();
                Thread.Sleep(4000);
            }
        }
    }

    public class Threadout
    {
        private Thread thread;
        private Signal signal;

        public Threadout()
        {
            signal = new Signal();
            thread = new Thread(new ThreadStart(TestThread));
            thread.Priority = ThreadPriority.Normal;
            thread.Start();
        }

        private void TestThread()
        {
            while (true)
            {
                signal.Wait(1);
                Thread.Sleep(100);
            }
        }
    }

    public class Timeout
    {
        private Timer timer;
        private Signal signal;

        public Timeout()
        {
            signal = new Signal();
            timer = new Timer(TestTimer, null, 1000, 2000);
        }

        private void TestTimer(object state)
        {
            signal.Wait(2);
        }
    }
}

Could anyone else try my code to see if you also got the same problem with Debug.GC()??

I am feeling that 4.2 is not as stable as 4.1.

My application freezes after 30 minutes of running fine and reboots.

This never happend on 4.1 but then I run on USBizi so there may be some buggs in G120.

I also get BSOD which is quite annoying.

Problem is that customer is picking up the product tomorrow and I can’t deliver a product that hangs after 30 minutes…

I also noticed that Glitch filter should be implemented in 4.2.7.0 but I am getting argument exception when setting it to true.

We are looking into this now, and will let you know as soon as we determine the problem.

Great!

I have tested a bit more and I wonder what will happen when the GC kicks in by it self to free the heap if WaitHandler is the problem when running GC manual?

Is it the same function/method that is call behind the scen?

Could this in the long run caus a deadlock???

Just some thoughts about my application freezing.

In my code I have about 8 WaitHandlers…

We found the fix for this issue. It was incredibly simple but hard to find. We will be doing some more testing to ensure that it is completely fixed.

Go Steven! Go Steven!..

:slight_smile: