home *** CD-ROM | disk | FTP | other *** search
/ Chip 1995 March / CHIP3.mdf / programm / prog4 / answers / ch27_2.ada < prev    next >
Encoding:
Text File  |  1991-07-01  |  1.6 KB  |  72 lines

  1.                         -- Chapter 27 - Programming example 2
  2. with Text_IO;
  3. use Text_IO;
  4.  
  5. procedure CH27_2 is
  6.  
  7. task type SHORT_LINE is
  8. end SHORT_LINE;
  9.  
  10. task type LONG_LINE is
  11. end LONG_LINE;
  12.  
  13. type LONG_POINT is access LONG_LINE;
  14.  
  15. Cow, Dog, Pig          : SHORT_LINE;
  16. Elephant, Hippopotamus : LONG_POINT;
  17. Horse                  : LONG_POINT := new LONG_LINE;
  18.  
  19. task body SHORT_LINE is
  20. begin
  21.    for Index in 1..4 loop
  22.       delay 0.0;
  23.       Put_Line("This is a short line");
  24.    end loop;
  25. end SHORT_LINE;
  26.  
  27. task body LONG_LINE is
  28. begin
  29.    for Index in 1..3 loop
  30.       delay 0.0;
  31.       Put_Line("This is a much longer line to be displayed");
  32.    end loop;
  33. end LONG_LINE;
  34.  
  35. begin
  36.  
  37.    Put_Line("This is an example of use of a task type");
  38.    Elephant := new LONG_LINE;
  39.    Hippopotamus := new LONG_LINE;
  40.  
  41. end CH27_2;
  42.  
  43.  
  44.  
  45. -- The task named Horse will begin execution at the same time
  46. --   that the main body of the program begins execution.
  47.  
  48. -- Exception never handled - program_error
  49.  
  50. -- Result of execution
  51.  
  52. -- This is an example of use of a task type
  53. -- This is a short line
  54. -- This is a short line
  55. -- This is a short line
  56. -- This is a short line
  57. -- This is a short line
  58. -- This is a short line
  59. -- This is a much longer line to be displayed
  60. -- This is a short line
  61. -- This is a short line
  62. -- This is a short line
  63. -- This is a much longer line to be displayed
  64. -- This is a short line
  65. -- This is a short line
  66. -- This is a short line
  67. -- This is a much longer line to be displayed
  68. -- This is a much longer line to be displayed
  69. -- This is a much longer line to be displayed
  70. -- This is a much longer line to be displayed
  71.  
  72.