我正在 Ada 中创建以下任务,我希望它包含一个告诉我缓冲区计数的过程。我怎样才能做到这一点?
package body Buffer is
task body Buffer is
size: constant := 10000; -- buffer capacity
buf: array(1.. size) of Types.Item;
count: integer range 0..size := 0;
in_index,out_index:integer range 1..size := 1;
begin
procedure getCount(currentCount: out Integer) is
begin
currentCount := count;
end getCount;
loop
select
when count<size =>
accept put(item: in Types.Item) do
buf(in_index) := item;
end put;
in_index := in_index mod size+1;
count := count + 1;
or
when count>0 =>
accept get(item:out Types.Item) do
item := buf(out_index);
end get;
out_index := out_index mod size+1;
count := count - 1;
or
terminate;
end select;
end loop;
end Buffer;
end Buffer;
当我编译这段代码时,我得到一个错误
声明必须在“开始”之前
参考getCount
过程的定义。