是否有“此”字样? Ada中的关键字? [英] Is there a "this" keyword in Ada?

查看:87
本文介绍了是否有“此”字样? Ada中的关键字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

具体来说,任务是否有办法获得对自身的引用?

Specifically, is there a way for a task to get a reference to itself?

例如:

task type someTask; 
type someTaskAccessor is access someTask;

task body someTask is
    pointerToTask : someTaskAccessor;
begin
    pointerToTask = this;
end someTask;


推荐答案

我建议的最明显的解决方案是声明一个任务开始时的集合(条目),您将对刚刚创建的任务的引用传递给该集合。另一种可能性是对您的任务类型使用判别式,其职责是告诉新任务它的位置(将对新任务的访问权传递给判别式)。不幸的是,我手头没有Ada编译器,所以我不能给您任何有效的示例。

the most evident solution i could suggest is to declare a rendez-vous (an entry) at the very beginning of your task, to which you pass a reference to the task just created. the other possibility is using a discriminant to your task type, whose role is to tell a new task where it is located (pass the access to the new task into the discriminant). unfortunately, i don't have an Ada compiler at hand so i can't give you any working example.

无论如何,根据您的评论:创建一个新的任务需要在某个地方进行处理,这时您还需要确定此新任务将进入双向链接列表的位置(创建新任务时,您至少需要知道一个现有任务,以便他们进行交流:他们不会神奇地发现自己)。当您有了新创建的任务及其左右同伴时,您可以利用这一时刻,告诉每个人是他们的邻居(再次使用集合点)。

anyway, based on your comment: the creation of a new task needs to be handled somewhere, at which point you will also need to determine where this new task will go into your doubly-linked list (you need to know at least one existing task when creating a new one in order for them to communicate: they won't discover themselves magically). you can take advantage of this moment, when you have the newly created task and its left and right peers, to tell everybody who are their neighbour (using a rendez-vous once again).

这篇关于是否有“此”字样? Ada中的关键字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆