From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,1d4203bfa2644439 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.66.79.105 with SMTP id i9mr2977202pax.34.1354717182267; Wed, 05 Dec 2012 06:19:42 -0800 (PST) Path: s9ni28998pbb.0!nntp.google.com!news.glorb.com!feeder.erje.net!us.feeder.erje.net!news2.arglkargh.de!news.mixmin.net!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Task with access to itself? Date: Wed, 5 Dec 2012 15:18:34 +0100 Organization: cbb software GmbH Message-ID: References: <8738zk7gge.fsf@adaheads.sparre-andersen.dk> Reply-To: mailbox@dmitry-kazakov.de NNTP-Posting-Host: kWJV5lTRAyCzy8lsfOrlcw.user.speranza.aioe.org Mime-Version: 1.0 X-Complaints-To: abuse@aioe.org User-Agent: 40tude_Dialog/2.0.15.1 X-Notice: Filtered by postfilter v. 0.8.2 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Date: 2012-12-05T15:18:34+01:00 List-Id: On Wed, 05 Dec 2012 14:53:53 +0100, Jacob Sparre Andersen wrote: > I would like to maintain a collection of tasks, where the tasks > themselves can register their availability. [...] > Any suggestions? Active object? type Active_Object is abstract new Ada.Finalization.Limited_Controlled with private; overriding procedure Initialize (Object : in out Active_Object); overriding procedure Finalize (Object : in out Active_Object); procedure Do_Stuff (Object : in out Active_Object) is abstract; private task type Worker (Object : not null access Active_Object'Class) is entry Stop; end Worker; type Active_Object is abstract new Ada.Finalization.Limited_Controlled with record Handler : not null access Worker := new Worker (Active_Object'Access); end record; ------------------------------------------------------------------------------------------- procedure Initialize (Object : in out Active_Object) is begin -- Register Object or else its task end Initialize; procedure Finalize (Object : in out Active_Object) is type Worker_Ptr is access all Worker; Ptr : Worker_Ptr; procedure Free is new Ada.Unchecked_Deallocation (Worker, Worker_Ptr) begin -- Unregister Object.Handler.Stop; while not Object.Handler'Terminated loop delay 0.001; end loop; Ptr := Object.Handler.all'Unchecked_Access; Free (Ptr); end Finalize; -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de