From: sdm7g@dale.acc.Virginia.EDU (Steve D. Majewski)
Subject: Re: VMS(4.5)-CRTL sleep() sometimes doesn't sleep
Date: 21 Jun 90 21:39:12 GMT [thread overview]
Message-ID: <1990Jun21.213912.28758@murdoch.acc.Virginia.EDU> (raw)
In-Reply-To: 1990Jun20.185657.27108@murdoch.acc.Virginia.EDU
Thanks to all those who responded to my problems.
To summarize what I have learned, both from my respondants and
from a little experimenting & debugging:
IN GENERAL:
Sleep( n ) CAN'T be relied upon to sleep n seconds.
It calls $SCHDWK & $HIBER. There are several events that cause a
state change from HIB and sleep does not check that the time has
actually expired, before returning "n" , making it appear to has
been successful. ( Actually, you should think of sleep() as pause()
with a timeout value ! - Is this implementation meant to capture
the bugs/features/behavior of the Unix vesion ? )
If you really want to "sleep" n seconds, use $SETIMR & $WAITFR.
SPECIFICALLY,
in my program, the other event that was waking sleep early was:
SYS$WAKE( &correlate_pid, 0 );
.
.
.
sleep( collect_time );
.
.
.
While debugging, the vfork()/execle() to create the correlation process
was not done, so that I could use the debugger. ( spawning a sub-process
with vfork()/execle() seems to work quit differently than LIB$SPAWN:
among other things, it seems to be fatal to the debugger. )
Thus, correlate_pid == 0, and as we all know, almost all of the system
services that use a PID, interpret PID=0 to mean "ME" , the calling
process.
WHY calling SYS$WAKE BEFORE calling sleep makes sleep wake early is
not obvious on the surface. I assume it has something to do with the
calls affecting the process scheduling rather than the process directly.
But a change to:
if ( correlate_pid ) SYS$WAKE( &correlate_pid, 0 );
seems to have fixed things.
I may STILL have to change to a $SETIMR/$WAITFR method of sleeping,
since this is a data collection program that relies on "sleep( 10 )"
actually getting 10 seconds of X-rays accumulated in a spectrometer!
( I don't need millisecond resolution guaranteed, it's not THAT
REALTIME, but I need to rely on it being better than a second, and
now that I know a bit about the inner workings of "sleep", I don't
trust it. - time to dig out the Big Black Book (VAX/VMS Internals &
Data Structures) and see what these system services actually DO ! )
-------------------------------------------------------------------------
Steven D. Majewski University of Virginia Physiology Dept.
sdm7g@virginia.edu Box 449 Health Sciences Center
(804) 982-0831 Charlottesville, VA 22908
next prev parent reply other threads:[~1990-06-21 21:39 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
1990-06-20 18:56 VMS(4.5)-CRTL sleep() sometimes doesn't sleep Steve D. Majewski
1990-06-21 21:39 ` Steve D. Majewski [this message]
1990-06-22 9:36 ` tp
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox