foo.adb 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. -- Copyright 2009-2022 Free Software Foundation, Inc.
  2. --
  3. -- This program is free software; you can redistribute it and/or modify
  4. -- it under the terms of the GNU General Public License as published by
  5. -- the Free Software Foundation; either version 3 of the License, or
  6. -- (at your option) any later version.
  7. --
  8. -- This program is distributed in the hope that it will be useful,
  9. -- but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. -- GNU General Public License for more details.
  12. --
  13. -- You should have received a copy of the GNU General Public License
  14. -- along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. procedure Foo is
  16. Value : Integer := 0;
  17. task type Caller is
  18. entry Initialize;
  19. entry Call_Break_Me;
  20. entry Finalize;
  21. end Caller;
  22. type Caller_Ptr is access Caller;
  23. procedure Break_Me is
  24. begin
  25. Value := Value + 1;
  26. end Break_Me;
  27. task body Caller is
  28. begin
  29. accept Initialize do
  30. null;
  31. end Initialize;
  32. accept Call_Break_Me do
  33. Break_Me;
  34. end Call_Break_Me;
  35. accept Finalize do
  36. null;
  37. end Finalize;
  38. end Caller;
  39. Task_List : array (1 .. 3) of Caller_Ptr;
  40. begin
  41. -- Start all our tasks, and call the "Initialize" entry to make
  42. -- sure all of them have now been started. We call that entry
  43. -- immediately after having created the task in order to make sure
  44. -- that we wait for that task to be created before we try to create
  45. -- another one. That way, we know that the order in our Task_List
  46. -- corresponds to the order in the GNAT runtime.
  47. for J in Task_List'Range loop
  48. Task_List (J) := new Caller;
  49. Task_List (J).Initialize;
  50. end loop;
  51. -- Next, call their Call_Break_Me entry of each task, using the same
  52. -- order as the order used to create them.
  53. for J in Task_List'Range loop -- STOP_HERE
  54. Task_List (J).Call_Break_Me;
  55. end loop;
  56. -- And finally, let all the tasks die...
  57. for J in Task_List'Range loop
  58. Task_List (J).Finalize;
  59. end loop;
  60. null; -- STOP_HERE_2
  61. end Foo;