home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / lang / cplus / 18285 < prev    next >
Encoding:
Text File  |  1992-12-22  |  3.9 KB  |  91 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!uunet.ca!ohrd!twriter
  3. From: twriter@rd.hydro.on.ca (Timothy Writer)
  4. Subject: Re: Give me safe C++
  5. Message-ID: <1992Dec21.215321.8088@rd.hydro.on.ca>
  6. Reply-To: twriter@rd.hydro.on.ca
  7. Organization: "Ontario Hydro - Research Division"
  8. References: <1992Dec14.190553.14838@mole-end.matawan.nj.us> <1992Dec17.192301.23525@ucc.su.OZ.AU> <1992Dec17.235544.5983@rd.hydro.on.ca> <1992Dec21.095145.13134@ucc.su.OZ.AU>
  9. Date: Mon, 21 Dec 92 21:53:21 GMT
  10. Lines: 79
  11.  
  12. maxtal@extro.ucc.su.OZ.AU (John MAX Skaller) writes:
  13.  
  14. >In article <1992Dec17.235544.5983@rd.hydro.on.ca> twriter@rd.hydro.on.ca writes:
  15. >>maxtal@extro.ucc.su.OZ.AU (John MAX Skaller) writes:
  16. >>
  17. >>>    Next, I feel NO language has addressed the concept
  18. >>>of coroutines (except possibly Simula?). C provides
  19. >>
  20. >>There was (is) a language called Concurrent Euclid which was invented at
  21. >>the University of Toronto some years ago.  In my opinion, it addressed
  22. >>the problem of concurrency (coroutines) quite effectively.  
  23.  
  24. >    In my thinking, processes differ from coroutines.
  25. >First, processes operate concurrently, and so must be synchronised,
  26. >whereas coroutines use a single thread of control that
  27. >swaps back and forward under the control of the coroutines
  28. >themselves (transfer of control is explicit).
  29.  
  30. It is trivial to simulate your style of coroutines with Euclid processes
  31. using Euclid's conditions and its companion signal and wait statements.
  32. It is rather more difficult to implement Euclid processes using
  33. coroutines as you have described them.
  34.  
  35. >    The other difference is that coroutines share the environment
  36. >they are instantiated in. If Unix processes cause the stack
  37. >to be duplicated, then coroutines cause the stack to fork.
  38.  
  39. Euclid processes are not UNIX processes, although you can implement UNIX
  40. processes with Euclid processes.  Euclid processes do share the same
  41. environment and the same address space.  Whether thay share the same
  42. stack or have their own would, I imagine, depend on the particular
  43. implementation.  They are more like a lightweight process mechanism than
  44. a traditional UNIX process, the key difference being that they are
  45. supported at the language level.
  46.  
  47. >>
  48. >>When the program starts up it immediately creates two processes
  49. >>(coroutines) up and down.  The output might look something like this.
  50. >>
  51. >>1 >2 >3 >2 >3 >4 >3 >2 >1 >0 >-1 >0 >...
  52.  
  53. >    Random. Coroutines, on the other hand, are completely
  54. >deterministic. They are like subroutines for which the
  55. >caller and callee cannot be distinguished. (Or rather,
  56. >the distinction is relative).
  57.  
  58. Its random for the simple example I gave but it doesn't have to be.
  59.  
  60. >>
  61. >>Euclid also provides a means of synchronizing processes using signals
  62. >>and conditions although I don't remember enough to describe it.
  63. >>
  64.  
  65. >    Coroutine are sometimes used to simulate processes.
  66. >However a proper coroutine facility would have to provide
  67. >the shared memory context and forked local context.
  68. >Of course this can be simulated using objects .. but simulations
  69. >are not the same as syntax. Inventing a syntax for filters
  70. >is not so hard .. but I've never got beyond that. Perhaps
  71. >objects are the only general solution?
  72.  
  73. I'm not sure I follow you.  I haven't tried to simulate your style of
  74. coroutines but I have tried to simulate Euclid style processes using C++
  75. classes and lightweight processes.  Emulating processes was easy, the
  76. hard part is fitting process synchronization into the object model.  My
  77. point in describing Euclid was simply to point out that there are
  78. languages that provide a proper coroutine facility.  There is no
  79. theoretical reason why C++ could not provide a suitable syntax; however,
  80. I doubt that such a syntax would be adopted into the language standard
  81. in the near future because of the difficuly of implementation esp. on
  82. some platforms.
  83.  
  84. Tim
  85.  
  86. -- 
  87. Tim Writer                 phone:  (416) 231-4111 ext. 6990
  88. Ontario Hydro Research Division         fax:    (416) 237-9285
  89. Toronto, Ontario             e-mail: twriter@rd.hydro.on.ca
  90. CANADA
  91.