Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a "this" keyword in Ada?

Tags:

this

ada

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;
like image 548
Landon Avatar asked Jan 01 '26 18:01

Landon


2 Answers

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).

like image 172
Adrien Plisson Avatar answered Jan 06 '26 14:01

Adrien Plisson


The package Ada.Task_Identification provides the Current_Task function to retrieve the current task's Task_ID.

like image 37
Marc C Avatar answered Jan 06 '26 14:01

Marc C



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!