From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f7344,6d50c88b54316cb9 X-Google-Attributes: gidf7344,public X-Google-Thread: f7cd1,6d50c88b54316cb9 X-Google-Attributes: gidf7cd1,public X-Google-Thread: 123a51,6d50c88b54316cb9 X-Google-Attributes: gid123a51,public X-Google-Thread: 1164f8,6d50c88b54316cb9 X-Google-Attributes: gid1164f8,public X-Google-ArrivalTime: 1990-06-22 11:36:54 PST Path: gmdzi!unido!mcsun!uunet!tut.cis.ohio-state.edu!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!aplcen!haven!uvaarpa!murdoch!news From: sdm7g@dale.acc.Virginia.EDU (Steve D. Majewski) Newsgroups: comp.os.vms,comp.sys.dec,vmsnet.misc,uva.vms Subject: Re: VMS(4.5)-CRTL sleep() sometimes doesn't sleep Keywords: sleep $HIBER $WAKE $SCHDWK CRTL Message-ID: <1990Jun21.213912.28758@murdoch.acc.Virginia.EDU> Date: 21 Jun 90 21:39:12 GMT References: <1990Jun20.185657.27108@murdoch.acc.Virginia.EDU> Sender: news@murdoch.acc.Virginia.EDU Followup-To: comp.sys.dec Organization: University of Virginia Xref: gmdzi comp.os.vms:25171 comp.sys.dec:2577 vmsnet.misc:69 Posted: Thu Jun 21 22:39:12 1990 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