简体   繁体   English

阿达左手的任务不得限制类型

[英]Ada left hand of assignment must not be limited type

I am at loss after spending hours on this. 花了好几个小时后,我感到很茫然。

Protected type declaration: 受保护的类型声明:

   protected type AdditionMachine is
      procedure setTask (Item : in WorkerTask);
      procedure getTask (Item : out WorkerTask);
      procedure calculate;
   private
      machineType : String (1 .. 1) := "A";
      job : workerTask;
   end AdditionMachine;

Task: 任务:

   task body SimpleTask1 is 
     Available     : Natural := ADDITION_MACHINES;
      Elements      : array (1 .. ADDITION_MACHINES) of AdditionMachine;
   begin
     loop
        select
           when Available > 0 =>
              accept getMachine (machine : out AdditionMachine) do
                  machine := Elements(Available);
                  Available := Available - 1;
              end getMachine;
        or
            accept addMachine (machine : in AdditionMachine) do
                 Available := Available + 1;
                 Elements(Available) := machine;
              end addMachine;
        end select;
     end loop;
   end  SimpleTask1;

At line Elements(Available) := machine; 在线Elements(Available) := machine; and machine := Elements(Available); machine := Elements(Available); I get "left hand of assingment must not be limited type" 我得到“左手的assingment一定不能限制类型”

I have no idea how to fix this, I've found nothing when I googled, can anyone help? 我不知道如何解决这个问题,当我用Google搜索时,我什么也没找到,有人可以帮忙吗?

edit: I now know that protected types are limited, but how do I accomplish a pool of protected objects without something like above? 编辑:我现在知道受保护的类型是有限的,但是如何在没有上述内容的情况下完成受保护对象池?

From ARM 7.5 , Limited Types, ARM 7.5 ,有限类型,

A limited type is (a view of) a type for which copying (such as for an assignment_statement) is not allowed. 限制类型是(视图)不允许复制(例如,对于assignment_statement)的类型。 A nonlimited type is a (view of a) type for which copying is allowed. 无限制类型是允许复制的(视图a)类型。

However, you are allowed to copy accesses to limited objects. 但是,你允许复制访问有限的对象。

So, if you have declared 所以,如果你已经申报了

protected type AdditionMachine is
   ...
end AdditionMachine;
type AdditionMachine_Access is access AdditionMachine;

you can write something like this (I haven't tested it): 你可以写这样的东西(我还没有测试过):

task body SimpleTask1 is 
   Available : Natural := ADDITION_MACHINES;
   Elements  : array (1 .. ADDITION_MACHINES) of AdditionMachine_Access
     := (others => new AdditionMachine);
begin

You'll need to take care of deallocating the allocated objects when you've done with them (if the program needs to run indefinitely, anyway). 当你完成它们时,你需要注意释放已分配的对象(如果程序需要无限期地运行)。 I don't think there'll be a problem with protected objects (but what happens if a task is waiting on a PO that you deallocate?), and recent GNATs are OK with deallocating tasks provided the tasks have open terminate alternatives, ARM 9.7.1 , or have already terminated - perhaps by being aborted). 我不认为受保护对象会出现问题(但如果任务正在等待您解除分配的PO上会发生什么?),并且最近的GNAT可以解除分配任务,前提是任务具有开放终止替代方案, ARM 9.7 .1 ,或已经终止 - 也许是通过中止)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM