Specifically, is there a way for a task to get a reference to itself?
For example:
task type someTask;
type someTaskAccessor is access someTask;
task body someTask is
pointerToTask : someTaskAccessor;
begin
pointerToTask = this;
end someTask;
the most evident solution i could suggest is to declare a rendez-vous (an entry) at the very beginning of your task, to which you pass a reference to the task just created. the other possibility is using a discriminant to your task type, whose role is to tell a new task where it is located (pass the access to the new task into the discriminant). unfortunately, i don't have an Ada compiler at hand so i can't give you any working example.
anyway, based on your comment: the creation of a new task needs to be handled somewhere, at which point you will also need to determine where this new task will go into your doubly-linked list (you need to know at least one existing task when creating a new one in order for them to communicate: they won't discover themselves magically). you can take advantage of this moment, when you have the newly created task and its left and right peers, to tell everybody who are their neighbour (using a rendez-vous once again).
The package Ada.Task_Identification provides the Current_Task function to retrieve the current task's Task_ID.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With