代码(Ada)2. TASKS

• 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;  -- 推迟到这个时间点
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容