Article View: borland.public.cppbuilder.nativeapi
Article #11341Re: Sleep time resolution
From: Rob
Date: Fri, 13 Feb 2004 21:20
Date: Fri, 13 Feb 2004 21:20
23 lines
2001 bytes
2001 bytes
"Malcolm Smith" <mjfreelancing@optusnet.com.au> wrote in message news:402b6ed2$1@newsgroups.borland.com... > I made an observation a long time ago that Sleep(0) causes real problems in > tight loops. Change it to Sleep(1) - all problems go away. > The reason that Sleep(0) can cause problems in tight loops is that all it does is yield the processor to other threads in priority order. Higher priority threads will often get CPU resources, with or without the Sleep(0) as your thread will be preempted. Threads at equal priority will get some access to CPU resources, but will often be starved of CPU resources (eg other user apps will be starved by one that hogs resources). Lower priority threads are very likely to be starved of CPU resources (although the scheduler sometimes does things to address that, it often elects not to). Changing to Sleep(1) simply means that you slow down your loops, so that other apps have a larger timeslice in which to run and in which your tight loop is guaranteed not to. The flip side of that is that your "tight loop" will take longer to complete.
Technical Details
Message-ID:
<402d421b@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<402b4f78$1@newsgroups.borland.com> <402b6ed2$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,3e6954a6a5dc7821 X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2004-02-13 13:40:26 PST From: "Rob" <nospam@nonexistant.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <402b4f78$1@newsgroups.borland.com> <402b6ed2$1@newsgroups.borland.com> Subject: Re: Sleep time resolution Date: Sat, 14 Feb 2004 07:50:59 +1030 Lines: 26 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4922.1500 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4925.2800 NNTP-Posting-Host: 211.26.118.86 Message-ID: <402d421b@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1076707867 211.26.118.86 (13 Feb 2004 13:31:07 -0800) Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail