Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asynchronous Ada中的Fire-and-forget进入/接受机制_Asynchronous_Ada - Fatal编程技术网

Asynchronous Ada中的Fire-and-forget进入/接受机制

Asynchronous Ada中的Fire-and-forget进入/接受机制,asynchronous,ada,Asynchronous,Ada,Ada中是否存在一种“火与忘”机制模式?当我调用任务条目时,我不希望在处理消息之前阻止调用方。我希望任务是异步的。我试过的是 loop select accept xxx(params) do -- save the parameters in a queue end accept; ... else -- pick the next item off the queue and process

Ada中是否存在一种“火与忘”机制模式?当我调用任务条目时,我不希望在处理消息之前阻止调用方。我希望任务是异步的。我试过的是

loop
    select
        accept xxx(params) do
           -- save the parameters in a queue
        end accept;
        ...
    else
        -- pick the next item off the queue and process it
    end select;
end loop;

它看起来像一个笨拙的机械装置。也许用火和遗忘这个词是错误的。我还尝试了一个任务填充队列,另一个任务从队列中删除条目。是否有更好的方法在Ada中实现异步任务。

如果您使用的是Ada 2012,那么方法就是使用(或版本):您的用户代码调用
排队
,您的服务器任务调用
出列
,如果队列为空,则会阻塞

如果不是,通常的方法是使用您自己的受保护对象来封装队列(Ada 2012包就是这样做的)。差不多

package Parameters is new Ada.Containers.Vectors (Positive, Parameter);
protected Queue is
   procedure Put (P : Parameter);
   entry Get (P : out Parameter);
private
   The_Queue : Parameters.Vector;
end Queue;

protected body Queue is
   procedure Put (P : Parameter) is
   begin
      The_Queue.Append (P);
   end Put;
   entry Get (P : out Parameter) when not The_Queue.Is_Empty is
   begin
      P := The_Queue.First_Element;
      The_Queue.Delete_First;
   end Get;
end Queue;
然后

task body Server is
   P : Parameter;
begin
   loop
      Queue.Get (P);
      --  process P
   end loop;
end Server;

我想是时候更新我的编译器了——我仍然在使用Ada95。