Application hangs in SysUtils -> DoneMonitorSupport on exit

前端 未结 4 1090
南笙
南笙 2020-12-30 03:36

I am writing a very thread intensive application that hangs when it exits.

I\'ve traced into the system units and found the place where the program enters an infinit

4条回答
  •  旧巷少年郎
    2020-12-30 04:34

    I've worked around the bug in the following way:

    Copy System.SysUtils, InterlockedAPIs.inc and EncodingData.inc to my application directory and alter the following code in System.SysUtils:

      procedure CleanEventList(var EventCache: array of TSyncEventItem);
      var
        I: Integer;
      begin
        for I := Low(EventCache) to High(EventCache) do
        begin
          if InterlockedCompareExchange(EventCache[I].Lock, 1, 0) = 0 then
             DeleteSyncWaitObj(EventCache[I].Event);
          //repeat until InterlockedCompareExchange(EventCache[I].Lock, 1, 0) = 0;
          //DeleteSyncWaitObj(EventCache[I].Event);
        end;
      end;
    

    I also added this check at the top of System.SysUtils to remind me to update the System.SysUtils file if I change Delphi versions:

    {$IFNDEF VER230}
    !!!!!!!!!!!!!!!!
    You need to update this unit to fix the bug at line 19868
    See http://stackoverflow.com/questions/14217735/application-hangs-in-sysutils-donemonitorsupport-on-exit
    !!!!!!!!!!!!!!!!
    {$ENDIF}
    

    After these changes my application shuts down correctly.

    Note: I tried adding "ReportMemoryLeaksOnShutdown" as LU RD suggested, but on shutdown my app entered a race condition popping up numerous runtime error dialogs. A similar thing happens when I try EurekaLog's memory leak functionality.

提交回复
热议问题