home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!spool.mu.edu!agate!ucbvax!lrw.com!leichter
- From: leichter@lrw.com (Jerry Leichter)
- Newsgroups: comp.os.vms
- Subject: re: Re: Recursion in Vax Fortran
- Message-ID: <9301201734.AA18357@uu3.psi.com>
- Date: 20 Jan 93 16:34:07 GMT
- Sender: usenet@ucbvax.BERKELEY.EDU
- Organization: The Internet
- Lines: 58
-
-
- The issue of recursion in VMS Fortran has worried me for a while. In
- doing some real-time programming I need to monitor a process every so
- often and am using the sys$setimr() routine to do it. The ast calls
- itself until some external event occurs and I execute a sys$cantim().
- The problem is that the ast routine looks like it is calling itself
- within the call to sys$setimr(), as seen below. My simplistic
- solution has been to create a dummy routine (also below). This
- solution has worked fine for several years, but now I wonder whether
- there is a safer solution?
-
- ! update routine for FOLLOW command
- subroutine follow_update_ast( ident)
- common /timer/ delta_time(2)
- integer delta_time, ident, sys$setimr
- external dum_follow_ast
- ! executable code
- call update_screen
- istat = sys$setimr(%val( 0), delta_time,
- 1 dum_follow_ast, ident) ! motors still moving
- if (.not. istat) call lib$signal( %val( istat))
- return
- end
- !**************************************************************
- subroutine dum_follow_ast( ident)
- integer*4 ident
- call follow_update_ast( ident)
- return
- end
-
- Your code is NOT an example of recursion. There will only be one active
- instance of follow_update_ast at a time; the call to SYS$SETIMR merely
- requests that the same routine be called again later. Even if the timer
- goes off immediately, the resulting AST can't be delivered because you are
- already IN an AST routine, so delivery is blocked; it won't be unblocked until
- follow_update_ast returns, dismissing the AST. Of course, at that point it's
- OK to call it again - there will still be only one active instance at a time.
-
- If follow_update_ast were a function rather than a subroutine, you'd have a
- syntactic problem: Within the text of the function, the name of that function
- acts as a variable (to receive the return value), so cannot be used to refer
- to the function itself. With a subroutine, which doesn't return a value,
- in principle there should be no problem; but a couple of quick experiments
- reveal that FORTRAN will not let you use the name of a subroutine in a call
- within the subroutine itself. One obvious trick - declaring follow_update_ast
- as external within its own code - also fails.
-
- The code you've got is correct and will work, since there is no real
- recursion. It costs you one additional procedure call every time the timer
- AST goes off, which is probably not worth worrying about. If it were to
- become a problem, you could have code outside of follow_update_ast stash its
- address in a common block. follow_update_ast would see it as, say, variable
- MYSELF, and you'd pass %VAL(MYSELF) to SYS$SETIMR.
-
- If there's some more direct way to do this, I'm sure some experience VAX
- FORTRAN hacker out there will let us know.
- -- Jerry
-
-