Ada Tasks: Pointers in Task Records

I want to create a task type (for example, a task type called "computer") with some task entries in Ada. I want to create a task record with an input parameter of type "this is access to the entire computer", that is, a pointer to the type of task. Is it possible?

I tried to do something like this:

task type computer; type computer_ptr is access all computer; task type computer is entry init(a: computer_ptr); end computer; 

It has been suggested here . Unfortunately, this does not work: GNAT says the declarations are "computer" conflict.

Can anyone think of how to achieve what I want to do?

+4
source share
1 answer

Using task type computer; , you declare a task type computer without any entries. After that, you declare another type of task with the same name.

If you want to "forward" the type of task (as needed for the type of access), you just have to write type computer; as for any other type. This is an incomplete type and can be populated with a task type declaration.

So your example should look like this:

 type computer; type computer_ptr is access all computer; task type computer is entry init (a: computer_ptr); end computer; 
+5
source

Source: https://habr.com/ru/post/1412373/


All Articles