Skip to content

Commit 51b2b17

Browse files
committed
Adding subsection on Tasking_Check
1 parent 7e579a0 commit 51b2b17

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

content/courses/advanced-ada/parts/control_flow/exceptions.rst

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,8 @@ This table shows all language-defined checks and the associated exceptions:
296296
+-----------------------------+-------------------------+
297297
| :ada:`Storage_Check` | :ada:`Storage_Error` |
298298
+-----------------------------+-------------------------+
299+
| :ada:`Tasking_Check` | :ada:`Tasking_Error` |
300+
+-----------------------------+-------------------------+
299301

300302
In addition, we can use :ada:`All_Checks` to refer to all those checks above at
301303
once.
@@ -970,7 +972,58 @@ checks fails and raises a :ada:`Storage_Error` exception.
970972
:ada:`Tasking_Check`
971973
~~~~~~~~~~~~~~~~~~~~
972974

975+
The :ada:`Tasking_Check` ensures that all tasks have been activated
976+
successfully and that no terminated task is called. If the check fails, a
977+
:ada:`Tasking_Error` exception is raised.
978+
979+
.. note::
980+
981+
This concept was introduced in Ada 2022. It was created to group all checks
982+
that might raise the :ada:`Tasking_Error` exception.
983+
984+
Let's look at a simple example:
985+
986+
.. code:: ada run_button project=Courses.Advanced_Ada.Control_Flow.Exceptions.Checks_And_Exceptions.Tasking_Check_Error
987+
:class: ada-run-expect-failure
988+
989+
package Workers is
990+
991+
task type Worker is
992+
entry Start;
993+
end Worker;
994+
995+
end Workers;
973996

997+
with Ada.Text_IO; use Ada.Text_IO;
998+
999+
package body Workers is
1000+
1001+
task body Worker is
1002+
begin
1003+
Put_Line ("Task has started.");
1004+
delay 1.0;
1005+
Put_Line ("Task has finished.");
1006+
end Worker;
1007+
1008+
end Workers;
1009+
1010+
with Ada.Text_IO; use Ada.Text_IO;
1011+
with Workers; use Workers;
1012+
1013+
procedure Show_Tasking_Check_Error is
1014+
W : Worker;
1015+
begin
1016+
Put_Line ("W.Start...");
1017+
W.Start;
1018+
Put_Line ("Finished");
1019+
end Show_Tasking_Check_Error;
1020+
1021+
In this example, the body of :ada:`Worker` doesn't have an :ada:`accept`.
1022+
Therefore, no rendezvous can happen for the :ada:`W.Start` call. Since the
1023+
task eventually terminates (as you can see in the user messages), the call
1024+
to :ada:`Start` constitutes a call to a terminated task. This condition is
1025+
checked by the :ada:`Tasking_Check`, which fails in this case, thereby
1026+
raising a :ada:`Tasking_Error`.
9741027

9751028

9761029

0 commit comments

Comments
 (0)