[DUG] Hang during Sleep

Jolyon Smith jsmith at deltics.co.nz
Wed May 16 09:05:30 NZST 2012


> Still wondering how a sleep can hang.

This is actually quite easily explained.

Sleep() is an indication to the Windows thread scheduler that your thread
is willing to relinquish whatever timeslice it currently has.  Whether and
when that thread get's another bite at the CPU is now in the hands of the
Windows Scheduler.

"Sleep(100)" comes with no guarantee that your thread will resume execution
after 100 milliseconds, all it ensures is that your thread stops running
and absolutely won't run again for AT LEAST that time (give or take,
subject to clock resolution).  If there are other higher priority threads
demanding access to the CPU then your thread can easily find itself being
shunted to the bottom of the queue until those threads have done ALL their
work.

Given the nature of the application you describe, which seems to involve
some sort of multimedia content, I am guessing that even within your
process - never mind anything else that might be running on the same
machine - you have one or more other threads that you have most likely set
to higher than normal priority - the nature of multimedia being what it is,
you may even have a "realtime" priority thread in the mix somewhere.

That would easily explain why when you relinquish your main UI thread's
timeslice it doesn't get a look-in until much, much later than you are
expecting.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://listserver.123.net.nz/pipermail/delphi/attachments/20120516/0e6b460f/attachment.html 


More information about the Delphi mailing list