opensubscriber
   Find in this group all groups
 
Unknown more information…

d : delphi@listserver.123.net.nz 15 May 2012 • 11:15AM -0400

Re: [DUG] Hang during Sleep
by Ross Levis

REPLY TO AUTHOR
 
REPLY TO GROUP




I think now from memory, the problem was someone clicking a button while in the sleep loop.  It was rare but was causing some sort of deadlock.  What I could try is to set the mainform.enabled := false at the top of the procedure and enable at the bottom to prevent that situation and put Application.ProcessMessages back.  I’ll give that a go.



Cheers.



From: Ross Levis [mailto:ross@stat...]
Sent: Tuesday, 15 May 2012 3:02 p.m.
To: 'NZ Borland Developers Group - Delphi List'
Subject: RE: [DUG] Hang during Sleep



I was using ProcessMessages in the sleep loop but it was causing problems and was removed.  I don’t recall the problem now but I think some event was being executed while in the loop and caused some problem.  I went to some trouble to not use it as you will see below.



But I might try adding it back for this user and see if it helps.



Here is the procedure the sleep function is in.



procedure StudioForm.LoopSleep(Duration: Integer);

var

  TickCount, LastCount, StartCount: Cardinal;

  TimerStatus: Boolean;

  Msg: TMsg;

begin

  TimerStatus := Timer.Enabled;

  Timer.Enabled := False;

  TickCount := GetTickCount;

  StartCount := TickCount;

  LastCount := TickCount;

  while GetTickDiff(StartCount,TickCount) <= Duration do

  begin

     Sleep(5);

     if GetTickDiff(LastCount,TickCount) >= 20 then // update every 20ms

     begin

       LastCount := TickCount;

        TimerTimer(nil); // update elapsed, VU, etc

        PeekMessage(Msg, StudioForm.Handle , 0, 0, PM_NOREMOVE); // tells Windows 7 app is not hung

        StudioForm.Update;

     end;

     TickCount := GetTickCount;

  end;

  Timer.Enabled := TimerStatus;

end;



GetTickDiff is a small Indy function which handles the situation if the tick count rolls over to 0 after 49 days.



Regards,

Ross.



From: delphi-bounces@list... [mailto:delphi-bounces@list...] On Behalf Of Pieter De Wit
Sent: Tuesday, 15 May 2012 5:26 a.m.
To: NZ Borland Developers Group - Delphi List
Subject: Re: [DUG] Hang during Sleep



Ross Levis <ross@stat...> wrote:

Hi Pieter



Bugreport.txt is attached.



It is a media player, and there are short pauses in some areas, such as to wait for the player process to come back from executing a command before executing another one.



The player itself is a separate process controlled by this one using shared memory.



The sleep is in a procedure which loops around for a set period (100ms in this case) with a sleep(5) and a MainForm.Update so VU meters continue moving.



Cheers,

Ross.



From: delphi-bounces@list... [mailto:delphi-bounces@list...] ! On Behalf Of Pieter De Wit
Sent: Monday, 14 May 2012 9:47 p.m.
To: NZ Borland Developers Group - Delphi List; 'NZ Borland Developers Group - Delphi List'
Subject: Re: [DUG] Hang during Sleep



Ross Levis <ross@stat...> wrote:

Perhaps someone can offer some clues to the problem.  A user is experiencing a hang during a Sleep(5) function!  It’s Win7 64-bit Hyperthreaded Intel 4 core CPU.



With MadExcept, it is showing the following…

!



exception message : The application seems to be frozen.

main thread ($9f4):

771dfd6a ntdll.dll                            NtDelayExecution

75ce31b5 KERNELBASE.dll                       SleepEx

75c! e3a86 KERNELBASE.dll                       Sleep

005dc66b SPLStudio.exe  StudioMain  6808   +9 LoopSleep



3 known threads are sitting at a Synchronize/NtWaitForSingleObject waiting for the current procedure in the main form to finish, which is sitting at Sleep(5).  I would expect that.



Another thread is also sitting at NtWaitForSingleObject but it doesn’t say what the thread class name is so not sure what ! it is.



Another unknown thread is at NtWaitForMultipleObjects.



And another unknown t! hread is at NtWaitForWorkViaWorkerFactory.



I know about the 3 threads waiting at Synchronize, but they shouldn’t be a problem.



What can cause a Sleep(5) to hang for over 90 seconds?



I can send the full bugreport.txt file if useful.



Thanks,

Ross.


Hi Ross,

Bugreport.txt will be usefull plus a short desc as to why you sleeping and what the app is waiting for?

Cheers,

Pieter

--
Sent from my Android phone. Please excuse my brevity.


Hi Ross,

I view you bug report on my mobile, so i might have missed it, but run application.processmessage (); before your sleep and after as well.

Cheers

Pieter
--
Sent from my Android phone with K-9 Mail. Please excuse my brevity.


Bookmark with:

Delicious   Digg   reddit   Facebook   StumbleUpon

Related Messages

opensubscriber is not affiliated with the authors of this message nor responsible for its content.