home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / programm / 3347 < prev    next >
Encoding:
Text File  |  1992-12-22  |  4.3 KB  |  84 lines

  1. Newsgroups: comp.programming
  2. Path: sparky!uunet!spool.mu.edu!agate!linus!linus.mitre.org!boole.mitre.org!crawford
  3. From: crawford@boole.mitre.org (Randy Crawford)
  4. Subject: Re: reentrant code
  5. Message-ID: <1992Dec22.050426.17583@linus.mitre.org>
  6. Sender: news@linus.mitre.org (News Service)
  7. Nntp-Posting-Host: boole.mitre.org
  8. Organization: The MITRE Corporation, McLean, VA
  9. References: <1992Dec14.160110.26338@linus.mitre.org> <1484@eouk13.eoe.co.uk>
  10. Date: Tue, 22 Dec 1992 05:04:26 GMT
  11. Lines: 71
  12.  
  13. In article <1484@eouk13.eoe.co.uk> pwestlak@eoe.co.uk (Peter Westlake) writes:
  14. >Randy Crawford (crawford@boole.mitre.org) wrote:
  15. >: 
  16. >: In article <1992Dec13.221314.26971@nntpd.lkg.dec.com>, mjg@ktbush.ogo.dec.com (Michael J. Grier) writes:
  17. >: > 
  18. >: > In article <1992Dec13.051634.14815@linus.mitre.org>, crawford@boole.mitre.org (Randy Crawford) writes:
  19. >: > |(Unattributed) wrote:
  20. >: > |>
  21. >: > |>>The problems of reentrancy are a bit different from concurrency. 
  22. >: > |>
  23. >: > |>True, but reentrancy is irrelevant unless concurrency in some form (like
  24. >: > |>context switching) is involved.
  25. >: > 
  26. >: >    Untrue.  Consider a module which implements an abstraction of a queue
  27. >: > or other searching structure, which provides a service for iteration on the
  28. >: > data structure.  If you specify the service such that the caller provides
  29. >: > a function to execute for each element in the structure, there is again
  30. >: > a need for reentrancy controls of some fashion.
  31. >: 
  32. >: Only if one part of the search cannot continue to completion before another
  33. >: part begins (or resumes).  This is still concurrency (or concurrent sub-
  34. >: tasks) no matter how you look at it.  When you have communicating concurrent
  35. >: threads/processes/tasks/contexts/callbacks, you have concurrency.
  36. >
  37. >This sounds more like recursion than concurrency.  Yes, there are several 
  38. >activations of the access function on the stack at the same time, but this 
  39. >does not constitute concurrency any more in this case (passing in functions 
  40. >to be called back) than it does when recursing by less devious means.
  41.  
  42. In only one sense could my definition be interpreted as recursion.  Given two
  43. tasks, A and B, after A begins execution and then stops, and B begins, B must
  44. eventually end before A does.  If A were to complete before B, you wouldn't
  45. have true recursion, since recursion is necessarily nested such that the parent
  46. task will always complete no earlier than the child.  After all, if A were 
  47. defined recursively using B, A could not be computed until after B was 
  48. computed and the result used to compute A.
  49.  
  50. Of course, if the two tasks _were_ recursive and shared a common resource, 
  51. you'd have a unresolvable deadlock problem -- task B must wait for parent A to 
  52. complete because B cannot use the shared resource until parent A finishes 
  53. using it, but A cannot continue execution until after B completes and produces
  54. the recursive result needed by A.  This is a really good example of bad design.
  55.  
  56. As Mr. Grier put it:
  57. > Consider a module which implements an abstraction of a queue
  58. > or other searching structure, which provides a service for iteration on the
  59. > data structure.  If you specify the service such that the caller provides
  60. > a function to execute for each element in the structure, there is again
  61. > a need for reentrancy controls of some fashion.
  62.  
  63. Here, reentrancy is necessary only if there are one or more data shared among 
  64. these search callbacks to which they might write asynchronously, interfering 
  65. with each other's state.  In that case, I still see this as a concurrency 
  66. problem (and certainly a reentrancy problem too).  
  67.  
  68. To better define my terms, I think that reentrancy exists to serve concurrency,
  69. and as such, you cannot have reentrancy without concurrency, but you can have 
  70. concurrency without reentrancy when no shared data is vulnerable.  
  71.  
  72. To pick a nit.
  73.  
  74. (BTW.  I agree with the earlier poster who suggested that I was confusing 
  75. context switching with sticky bits and memory swapping.  I meant to describe
  76. it as `context' swapping in working set terms, not in terms of active memory 
  77. or the physical movement of memory.  Obviously, modern Unixen do not use the
  78. sticky bit for such things.)
  79. -- 
  80.  
  81. | Randy Crawford        crawford@mitre.org        The MITRE Corporation
  82. |                                                 7525 Colshire Dr., MS Z421
  83. | N=1 -> P=NP           703 883-7940              McLean, VA  22102
  84.