home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / arch / 11980 < prev    next >
Encoding:
Internet Message Format  |  1992-12-29  |  4.4 KB

  1. Path: sparky!uunet!cs.utexas.edu!zaphod.mps.ohio-state.edu!saimiri.primate.wisc.edu!ames!olivea!decwrl!deccrl!news.crl.dec.com!rdg.dec.com!uvo.dec.com!e2big.mko.dec.com!nntpd.lkg.dec.com!ryn.mro4.dec.com!news
  2. From: pjdm@chmeee.enet.dec.com (Peter Mayne)
  3. Newsgroups: comp.arch
  4. Subject: Re: <None> (Should be Open Systems, bloody NEWS system...)
  5. Message-ID: <1992Dec29.012215.10632@ryn.mro4.dec.com>
  6. Date: 29 Dec 92 01:22:15 GMT
  7. References: <1992Dec23.050719.4047@ryn.mro4.dec.com> <id.CG2W.R8A@ferranti.com> <1992Dec23.212321.26522@ryn.mro4.dec.com> <id.SQ3W.IB6@ferranti.com>
  8. Sender: news@ryn.mro4.dec.com (USENET News System)
  9. Reply-To: Peter.Mayne@cao.mts.dec.com
  10. Organization: Digital Equipment Corporation
  11. Lines: 108
  12.  
  13.  
  14. In article <id.SQ3W.IB6@ferranti.com>, peter@ferranti.com (peter da silva) writes:
  15. >> Now, much of the run-time stuff in UNIX is non-reentrant.
  16. >
  17. >Much of the *C* run-time in *any* language is non-reentrant, and I would
  18. >be surprised if the VMS library was any better. If I get an AST while I'm
  19. >in the runtime (say, in the Fortran library in the middle of a formatted
  20. >I/O statement) I would expect dire consequences from calling the language
  21. >runtime. I have never written an asyncronous signal handler under any
  22. >operating system (out of UNIX, RMX, AmigaOS, and RSX-11) where I didn't
  23. >have to watch for that sort of thing. In RSX all you can do from an AST,
  24. >pretty much, is access memory.
  25. >
  26. >> In particular, the 
  27. >> use of errno springs to mind. If the AST (or APC) was introduced into the
  28. >> UNIX model,
  29. >
  30. >It's in there.
  31. >
  32. >> how can I use these non-reentrant routines safely in an AST
  33. >> routine without screwing things up?
  34. >
  35. >You can't. Can you really do
  36. >
  37. >    WRITE (*,10) AA
  38. > 10    FORMAT (1X,80A1)
  39. >
  40. >in an AST under VMS?
  41. >
  42.  
  43. The following is from the tempnam thread in comp.unix.ultrix. (Is open(2)
  44. considered part of the C run-time library, or the UNIX kernel?) Note that
  45. in the example given below, it doesn't even matter if open(2) is reentrant
  46. or not: you still have problems looking up the error. (See the sentence
  47. marked **.)
  48.  
  49. >> Begin quote >>
  50.  
  51. aaa@pixar.com (Tony Apodaca) writes:
  52.  
  53. >    The point is that a smart programmer
  54. >checks errno after every system call.
  55.  
  56.     The *wise* programmer checks the approriate return value of the
  57. system call, and if it returns a value indicating an error, then the errno
  58. value is used.
  59.  
  60.     Consider the following:
  61.  
  62.     int    fd;
  63.     fd = open("foo",O_RDWR|O_CREAT,0600);
  64.     if(errno != 0)
  65.         perror("foo");
  66.  
  67.     Versus:
  68.  
  69.     int    fd;
  70.     if((fd = open("foo",O_RDWR|O_CREAT,0600)) < 0)
  71.         perror("foo");
  72.  
  73.     Now, the manual page on open(2) states explicitly:
  74.  
  75. RETURN VALUE
  76.      The value -1 is returned if an error  occurs,  and  external
  77.      variable  errno  is  set to indicate the cause of the error.
  78.  
  79.     There's a good reason for writing your code this way. You are
  80. using the return value from the function, rather than a global value
  81. which can get stepped on by something unusual you don't know about.
  82. This means that your code doesn't have to care about what is a system
  83. call versus what is a library routine. Do you care? I don't. I just
  84. want to know if it didn't work right. Then I want to know why.
  85.  
  86. ** I believe that you can also run into problems if you have
  87. ** a signal handler that gets invoked, and resets errno in the period
  88. ** between your successful system call and your test for success. It's
  89. easier to just treat the system calls like a function call, and
  90. look at its return value. If you somehow think that using errno
  91. rather than having to declare a local to capture the return value is
  92. an optimization, you're mistaken.
  93.  
  94. mjr.
  95.  
  96. >> End Quote >>
  97.  
  98. Fixing this kind of problem would involve changing the model of "returning
  99. an error flag and a static errno". You could:
  100.  
  101. - return an error status rather than an error flag
  102. - signal on errors
  103. - call a "callback" routine on errors
  104. - fill in a program-provided "status block" (non-static "errno" equivalent)
  105.  
  106. Any one of these would probably be considered incompatible by a large number
  107. of UNIX style programmers (including DOS programmers and a lot of VMS
  108. programmers).
  109.  
  110. >-- 
  111. >Peter da Silva                                            `-_-'
  112. >Ferranti International Controls Corporation                'U` 
  113. >Sugar Land, TX  77487-5012 USA
  114. >+1 713 274 5180                            "Zure otsoa besarkatu al duzu gaur?"
  115.  
  116. PJDM
  117. --
  118. Peter Mayne                     | My statements, not Digital's.
  119. Digital Equipment Corporation   |
  120. Canberra, ACT, Australia        | "AXP!": Bill the Cat
  121.