* VMS(4.5)-CRTL sleep() sometimes doesn't sleep
@ 1990-06-20 18:56 Steve D. Majewski
1990-06-21 21:39 ` Steve D. Majewski
0 siblings, 1 reply; 3+ messages in thread
From: Steve D. Majewski @ 1990-06-20 18:56 UTC (permalink / raw)
PROBLEM:
VMS(4.5)-CRTL routine sleep() sometimes doesn't sleep !
I have made some modifications in a major real-time data
acquisition program we have running on a MicroVax II / VMS4.5
written in VMS C. There are 2 "child" processes ( one spawned
via vfork()/execl() and the other lib$spawn()-ed : it is in
fortran and execl() doesn't seem to pass args properly to non-C )
and 2 DECnet processes, and several connect-to-interrupt drivers.
One of the changes was to make what was formerly a DECnet task
into one of the local child processes.
In the main loop of the main process, it sleeps for n secs while
data is accumulating remotely. During this sleep(), the other
processes get their work done.
I tested most of the pieces seperately, but when I put them all
together, sleep didn't sleep and I got a bunch of write errors
from writing to a pipe/mailbox. ( I assume this is because without
the sleep, the child never has timeslice enough to consume any of
the data, and I've run out of I/O buffers to the mailbox. )
I tried replacing the sleep() call with LIB$WAIT() ( with the
appropriate floating point pointer arg. ) and the same thing
happens.
On the theory that something in the code is steping on something -
sleep works fine in other code - I stuck in several calls to
sleep before the main processing loop : ALL of them work fine, and
then sleep() fails when I need it to work.
sleep() returns the correct value - not a neg. error return.
Also once sleep() fails, LIB$WAIT also fails.
Running "show process /cont" in another window, I never see it
change state to "HIB" for the sleep calls, but I do see "HIB"
when the LIB$WAIT is called - But not long enough, i.e. less than
1 sec. instead of the 45 secs in the LIB$WAIT call. Of course, I
could just be missing the change with "show proc" .
What could be the cause of this behavior ?
I know that sleep() calls SYS$SCHDWK and then SYS$HIBER.
The only other cause of a wake up from SYS$HIBER I can find
documented is a SYS$WAKE call from another process. This I am
not INTENTIONALLY doing - I can't guarantee that it is not the
side effect of some other RTL function.
What about I/O completion or interrupts ?
Any CLues out there ?
-------------------------------------------------------------
- Steve Majewski
University of Virginia Physiology Dept. (804) 982-0831
sdm7g@virginia.edu
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: VMS(4.5)-CRTL sleep() sometimes doesn't sleep
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
1990-06-22 9:36 ` tp
0 siblings, 1 reply; 3+ messages in thread
From: Steve D. Majewski @ 1990-06-21 21:39 UTC (permalink / raw)
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: VMS(4.5)-CRTL sleep() sometimes doesn't sleep
1990-06-21 21:39 ` Steve D. Majewski
@ 1990-06-22 9:36 ` tp
0 siblings, 0 replies; 3+ messages in thread
From: tp @ 1990-06-22 9:36 UTC (permalink / raw)
In article <1990Jun21.213912.28758@murdoch.acc.Virginia.EDU>, sdm7g@dale.acc.Virginia.EDU (Steve D. Majewski) writes:
> 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.
Actually, this is the documented behavior of SYS$WAKE and SYS$HIBER. Look
in the VMS system services manuals. Any code that hibernates for a reason
(i.e. waiting for something to happen) MUST check that those conditions
have been met when it wakes, or it will run in correctly, just as you
report. If there is a pending wake when SYS$HIBER is called, it returns
immediately, as you have seen. (It doesn't count them by the way, there is
just a flag somewhere that says SYS$WAKE has been called.)
These services are defined this way to prevent race conditions. The normal
way to use them is to set AST's for the events you are interested in, and
then hibernate. The AST routine calls SYS$WAKE. When the AST routine
returns, the program falls out of SYS$HIBER.
Now think about what would happen if you set up the AST, but the event
happened BEFORE you actually got into SYS$HIBER. The way they currently
work, it would fall out of SYS$HIBER immediately, which is exactly the
right thing. If it didn't do this, it would process the AST and then
hibernate, never to wake up (unless another event will happen later that
does a SYS$WAKE).
--
Terry Poot <tp@mccall.com> The McCall Pattern Company
(uucp: ...!rutgers!ksuvax1!mccall!tp) 615 McCall Road
(800)255-2762, in KS (913)776-4041 Manhattan, KS 66502, USA
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~1990-06-22 9:36 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
1990-06-22 9:36 ` tp
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox