| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | async timer thread |
David Muir wrote in a message to Peter Fitzsimmons:
PF> What you want to do would be much easier with DosSleep.
PF> for(i=0; i<60; i++)
PF> DosSleep(1000);
DM> This would be acceptable if it there weren't other
DM> threads involved. but with numerous threads running, I fear
DM> there woud be too much lag in returning to this thread for
DM> the timing I want.
The trick, as I suggested perhaps not too clearly in my earlier message, is
to call DosSleep() but check the absolute time of day. If you need to wait
60 seconds, then my method is best. If you really need to be awakened at
precise 1-second intervals throughout the 60 seconds, then you do need a
system timer.
Here is the code I posted earlier, modified slightly to awaken every second:
time_t nsecs, fsecs;
nsecs = (time_t)60; /* number of seconds to wait */
fsecs = time(NULL) + nsecs; /* time at finish */
while (fsecs > time(NULL)) {
/* do stuff here */
DosSleep(1000UL);
}
While this may not awaken precisely every second, the aggregate of all
intervals will still only last nsecs overall, even if the machine is busy.
It might also be reasonable to set the thread which runs this code to time
critical priority, in which case you likely will be awakened every second.
PF> This all be "about" 60 seconds. If you need more precision, use
PF> DosStartTimer(), which does contain a 32bit sample in the online
DM> I had a look at this but I have the same problem (error
DM> 323 invalid semaphore handle). Using what function would I
DM> asign a semaphore for use by this call? (sorry I'm not
DM> using "C" and don't have the sample code you mentioned
DM> above).
If you are not using C, I doubt I can help you. Peter is right that, if
you need to be awakened each second, then you need to initiate a timer with
DosStartTimer(), and you need to have created an event semaphore using the
DosCreateEventSem() or DosOpenEventSem(). The thread being awakened must
explicitly reset the event semaphore each iteration using
DosResetEventSem() after being awakened, and must call DosWaitEventSem()
when it is ready to sleep again. Finally, you need to call DosStopTimer()
to release the timer and DosCloseEventSem() to release the semaphore. All
of these are 32-bit functions, and you need to be consistent.
PF> ref,and/or use DosSleep() and DosQuerySysInfo(QSV_MS_COUNT ..) in
PF> conjunction:
DM> I'll see if this does the trick. (assuming I can port it
DM> to VP ). Thanks for your help Peter.
I disagree with Peter that this approach would help you. All you would
have to do is call DosSleep(1) to achieve the same result, since you can
never sleep for less that a system timer tick anyway, and this is the value
you would get back from DosQuerySysInfo(QSV_MS_COUNT,...). I'm not too
sure what Peter was thinking on that.
-- Mike
---
* Origin: N1BEE BBS +1 401 944 8498 V.34/V.FC/V.32bis/HST16.8 (1:323/107)SEEN-BY: 50/99 78/0 270/101 620/243 711/401 409 410 413 430 808 809 934 955 SEEN-BY: 712/407 515 517 628 713/888 800/1 7877/2809 @PATH: 323/107 170/400 396/1 270/101 712/515 711/808 809 934 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.