🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #15807

Re: how to sleep 10 milisecond

#15807
From: Peter Elbertse
Date: Fri, 13 Jun 2003 06:47
41 lines
2506 bytes
Alternatively, but I'm really not sure about the accuracy, writing a simple thread with a while-loop
which checks for the diff. in two TDateTimes, and outside of the thread, using the WaitFor() to
detect when the thread is killed, could be a solution?

The thread would look something like:

TMyThread::Execute()
{
        // Create a Wait-Event for the period IP-Testing is done:
        TEvent *evWaitFor = new TEvent(NULL, true, false, "");

        // Loop until a 10ms. DateTime diff is acceived:
        while (Now() - dtStart < TDateTime(0,0,10,0)
           { evWaitFor->WaitFor(1); }

       // Free up memory:
       delete evWaitFor;
}

I haven't tested this, so I'm really not sure about the CPU usage and the accuracy, but maybe it's
worth trying.

Peter

"Wayne A. King" <waking@idirect.com> wrote in message
news:3ee946b1.47153496@newsgroups.borland.com...
> On Thu, 12 Jun 2003 20:05:14 +0200, "Boguslaw Fries" <B.Fries@luca-online.de>
> wrote:
>
> >I need a function, which sleeps my thread for 5 - 10 milisecond but not
> >more!
>
> Can't be guaranteed, since Windows won't *rigorously* preempt other
> tasks to allow yours to reactivate. Finer resolution than Sleep() may be
> achieved by using the multimedia timers. Consult the Win32 API help or
> MSDN.
>
> --
> Wayne A. King
> (ba994@torfree.net, wayne.king@ablelink.org,
>  waking@idirect.com, Wayne_A_King@compuserve.com)
Technical Details
Message-ID: <3ee97364@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-09!supernews.com!64.152.100.70.MISMATCH!sjc70.webusenet.com!news.webusenet.com!cyclone.bc.net!newsfeed.media.kyoto-u.ac.jp!newsfeed2.kddnet.ad.jp!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail
References: <3ee8c0df@newsgroups.borland.com> <3ee946b1.47153496@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,b6af681927951d13
X-Google-Attributes: gid10cc67,public
X-Google-ArrivalTime: 2003-06-12 23:56:08 PST
From: "Peter Elbertse" <zoetjuh@wanadoo.nl>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <3ee8c0df@newsgroups.borland.com> <3ee946b1.47153496@newsgroups.borland.com>
Subject: Re: how to sleep 10 milisecond
Date: Fri, 13 Jun 2003 08:47:00 +0200
Lines: 43
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
NNTP-Posting-Host: 212.238.183.121
Message-ID: <3ee97364@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1055486820 212.238.183.121 (12 Jun 2003 23:47:00 -0700)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-09!supernews.com!64.152.100.70.MISMATCH!sjc70.webusenet.com!news.webusenet.com!cyclone.bc.net!newsfeed.media.kyoto-u.ac.jp!newsfeed2.kddnet.ad.jp!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail