task_switch.adb 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. -- Copyright 2011-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 Task_Switch is
  16. -------------------
  17. -- Declaractions --
  18. -------------------
  19. task type Callee is
  20. entry Finito;
  21. end Callee;
  22. type Callee_Ptr is access Callee;
  23. task type Caller is
  24. end Caller;
  25. type Caller_Ptr is access Caller;
  26. procedure Break_Me;
  27. My_Caller : Caller_Ptr;
  28. My_Callee : Callee_Ptr;
  29. ------------
  30. -- Bodies --
  31. ------------
  32. task body Callee is
  33. begin
  34. -- Just wait until we are told to terminate this task.
  35. -- This is just to maintain this task alive.
  36. accept Finito do
  37. null;
  38. end Finito;
  39. end Callee;
  40. task body Caller is
  41. begin
  42. Break_Me;
  43. My_Callee.Finito;
  44. end Caller;
  45. procedure Break_Me is
  46. begin
  47. null;
  48. end Break_Me;
  49. begin
  50. -- Make sure to create the Callee task first... And then give it
  51. -- enough time to complete its activation phase before we start
  52. -- the Caller task.
  53. My_Callee := new Callee;
  54. delay 0.1;
  55. My_Caller := new Caller;
  56. end Task_Switch;