Ada任务:任务条目中的指针

Xav*_*ver 4 pointers ada task

我想在Ada中创建一个任务类型(例如名为"computer"的任务类型),其中包含一些任务条目.我想创建一个任务条目,其输入参数类型为"是访问所有计算机",即指向任务类型的指针.这是可能吗?

我试着这样做:

task type computer;
type computer_ptr is access all computer;    
task type computer is
  entry init(a: computer_ptr);
end computer;
Run Code Online (Sandbox Code Playgroud)

这是在这里提出的.不幸的是,这不起作用:GNAT说"计算机"的声明冲突.

谁能想到一种方法来实现我想做的事情?

oen*_*one 5

通过使用task type computer;,您声明一个完全没有条目的任务类型计算机.然后,您声明具有相同名称的另一个任务类型.

如果要"转发声明"任务类型(根据访问类型的需要),您应该type computer;像任何其他类型一样编写.这是一个不完整的类型,可以通过任务类型声明来完成.

所以你的例子应该是这样的:

type computer;
type computer_ptr is access all computer;
task type computer is
   entry init (a: computer_ptr);
end computer;
Run Code Online (Sandbox Code Playgroud)