home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / cplus / 18162 < prev    next >
Encoding:
Text File  |  1992-12-18  |  2.6 KB  |  103 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: <1992Dec17.235544.5983@rd.hydro.on.ca>
  6. Reply-To: twriter@rd.hydro.on.ca
  7. Organization: "Ontario Hydro - Research Division"
  8. References: <Bz2nDF.7B6@fiu.edu> <1992Dec12.145403.26483@ucc.su.OZ.AU> <1992Dec14.190553.14838@mole-end.matawan.nj.us> <1992Dec17.192301.23525@ucc.su.OZ.AU>
  9. Date: Thu, 17 Dec 92 23:55:44 GMT
  10. Lines: 91
  11.  
  12. maxtal@extro.ucc.su.OZ.AU (John MAX Skaller) writes:
  13.  
  14. >In article <1992Dec14.190553.14838@mole-end.matawan.nj.us> mat@mole-end.matawan.nj.us writes:
  15.  
  16. > [stuff deleted]
  17.  
  18. >    Next, I feel NO language has addressed the concept
  19. >of coroutines (except possibly Simula?). C provides
  20. >no simple exchange of control mechanism, although one
  21. >has to admit they can be emulated using objects in C++.
  22. >Yet many machines provide this facility, usually via
  23. >some exchange and link instruction.
  24.  
  25. There was (is) a language called Concurrent Euclid which was invented at
  26. the University of Toronto some years ago.  In my opinion, it addressed
  27. the problem of concurrency (coroutines) quite effectively.  Euclid is
  28. based on Turing, another University of Toronto language with strong
  29. similarities to Pascal.  To Turing, Euclid added monitors and processes.
  30. A process is simply a coroutine.  Monitors encapsulate critical data and
  31. the procedures for manipulating them.  As only one procedure is aloud to
  32. execute "in" a monitor, critical data is prevented from being
  33. simultaneously accessed by multiple procedures.
  34.  
  35. Here is a very silly example.  I forget much of the syntax but it
  36. illustractes the basic idea.
  37.  
  38. counter : Monitor
  39.  
  40.     var count : integer = 0
  41.  
  42.     procedure up()
  43.     begin
  44.         count = count + 1
  45.     end
  46.  
  47.     procedure down()
  48.     begin
  49.         count = count - 1
  50.     end
  51.  
  52.     precedure print()
  53.     begin
  54.         put(count)
  55.     end
  56.  
  57. end Monitor
  58.  
  59. process up()
  60. begin
  61.     counter.up
  62.     counter.print
  63. end
  64.  
  65. process down()
  66. begin
  67.     counter.down
  68.     counter.print
  69. end
  70.  
  71. When the program starts up it immediately creates two processes
  72. (coroutines) up and down.  The output might look something like this.
  73.  
  74. 1
  75. 2
  76. 3
  77. 2
  78. 3
  79. 4
  80. 3
  81. 2
  82. 1
  83. 0
  84. -1
  85. 0
  86. ...
  87.  
  88. Euclid also provides a means of synchronizing processes using signals
  89. and conditions although I don't remember enough to describe it.
  90.  
  91. Although there are strong similarities between Euclid and Pascal,
  92. Euclid is quite flexible.  In fact, I believe the same team that
  93. implemented Euclid also built an implementation of UNIX, called TUNIS,
  94. written entirley in Euclid.
  95.  
  96. Tim
  97.  
  98. -- 
  99. Tim Writer                 phone:  (416) 231-4111 ext. 6990
  100. Ontario Hydro Research Division         fax:    (416) 237-9285
  101. Toronto, Ontario             e-mail: twriter@rd.hydro.on.ca
  102. CANADA
  103.