【发布时间】:2016-12-08 13:21:58
【问题描述】:
首先让我们解决这个问题。我是 Ada 的初学者,我希望能够做到这一点的原因是因为我想编写优先级反转。
我已经加入了,
with Ada.Task_Identification;
我也做了一个任务类型:
task type tasktype1 is
pragma PRIORITY (20);
entry gotosleep;
end tasktype1;
我已经宣布了一项任务:
High : tasktype1;
现在我想将任务“高”的优先级更改为其他优先级。
我试过写:
High.Prority(1);
我会把它放在 main 的 begin 块中。
并声明了一个Task_ID。
A : Task_Id;
然后尝试使用A := Current_Task; 获取当前任务
然后将Priority(3,A); 放在电源开始处。
这是我所有的代码供参考:
with Ada.Text_IO, Ada.Integer_Text_IO, System, Ada.Task_Identification;
use Ada.Text_IO, Ada.Integer_Text_IO;
procedure Main is
task type tasktype1 is
pragma PRIORITY (20);
entry gotosleep;
end tasktype1;
pragma PRIORITY (3); -- This is the priority for the main program
High : tasktype1;
A : Task_Id;
task body tasktype1 is
begin
accept gotosleep do
Put("Cow is not sleeping");
end gotosleep;
end tasktype1;
begin
A := Current_Task;
Priority(3, A);
Put_Line("This is an example of use of a task type");
Put_Line("This is an example of use of a task type");
Put_Line("This is an example of use of a task type");
Put_Line("This is an example of use of a task type");
Put_Line("This is an example of use of a task type");
end Main;
【问题讨论】:
-
您可以在运行时使用
Ada.Dynamic_Priorities. Set_Priority设置任务优先级 - 请参阅ARM D.5.1(注意,没有您期望的配置文件Priority的子程序!)