How can I simulate an application freeze scenario?

I have a Windows Forms application that itself launches different threads to do different kinds of work. Sometimes all threads (including the user interface thread) become frozen, and my application stops responding. I decided that this could be a garbage collector problem, as the GC temporarily freezes all managed threads. To make sure that the streams just processed are frozen, I expand the unmanaged file, which is written to the "heartbeat" file with a time stamp every second, and this is not affected (i.e. Still running):

public delegate void ThreadProc();

[DllImport("UnmanagedTest.dll", EntryPoint = "MyUnmanagedFunction")]
public static extern void MyUnmanagedFunction();

[DllImport("kernel32")]
public static extern IntPtr CreateThread(
    IntPtr lpThreadAttributes,
    uint dwStackSize,
    IntPtr lpStartAddress,
    IntPtr lpParameter,
    uint dwCreationFlags,
    out uint dwThreadId);    

uint threadId;
ThreadProc proc = new ThreadProc(MyUnmanagedFunction);
IntPtr functionPointer = Marshal.GetFunctionPointerForDelegate(proc);
IntPtr threadHandle = CreateThread(IntPtr.Zero, 0, functionPointer, IntPtr.Zero, 0, out threadId);

My question is: how can I simulate this situation when all managed threads are paused but unmanaged threads keep spinning?

:

private void button1_Click(object sender, EventArgs e) {
    Thread t = new Thread(new ThreadStart(delegate {
        new Hanger();
        GC.Collect(2, GCCollectionMode.Forced);
    }));
    t.Start();
}
class Hanger{
    private int[] m_Integers = new int[10000000];
    public Hanger() { }
    ~Hanger() { Console.WriteLine("About to hang...");

    //This doesn't reproduce the desired behavior
    //while (true) ;

    //Neither does this
    //Thread.Sleep(System.Threading.Timeout.Infinite); 
    }
}

!

+3
4

DID . WinDbg , , GC . GC .

0

"" . , GC , , GC , , , . A () . , . GC. , .

, ~Hanger() , VM GC, , ~Hanger(), .

+1

, , , , GC.

, , Control.Invoke . , Invoke - ( - :))

0

Marek, concurrency, . , , .

- concurrency, , . , :

  • ?
  • What additional resources do your processes require (which already use some resources)?
  • What resources are needed to explicitly free a process that uses them?

Given this, if you have patterns of distribution of circular resources, you study the probable deadlock situation.

0
source

Source: https://habr.com/ru/post/1738711/


All Articles