• Every task independently executes the same sequence of statements.
• Every task instance has its own copy of local variables (which are initialized in the same way).
• Every task instance has its own set of independent interfaces, even though they all share the same syntactical form as given by the task type.
All task types are limited! That is tasks cannot be copied or tested for equality.
task [type] identifier [discriminant-part] [is
entry-declaration
...
entry-declaration
end identifier];
task body identifier is
declarative-part
begin
sequence-of-statements
exception
handler
...
handler
end identifier;
task 分为两个部分,一是declaration,一个是body。
declaration 用来entry。
body是有两部分:1. 变量的声明 (在begin之前)2. 程序的内容(在begin之后)
所以要分享一些数据,我们必须在task外面声明变量或者constant。
Ada会在运行begin之前先运行declare部分,以确保程序安全运行。
delay Delay_Per_Iteration; -- 推迟一段时间
delay until Start_Up_Time + i * Delay_Per_Iteration; -- 推迟到这个时间点