* Re: Using the "Terminated" aspect for a task passed to a generic
2018-04-23 14:20 Using the "Terminated" aspect for a task passed to a generic NiGHTS
@ 2018-04-23 15:40 ` AdaMagica
2018-04-23 16:23 ` Jeffrey R. Carter
` (3 subsequent siblings)
4 siblings, 0 replies; 8+ messages in thread
From: AdaMagica @ 2018-04-23 15:40 UTC (permalink / raw)
Am Montag, 23. April 2018 16:20:33 UTC+2 schrieb NiGHTS:
> Having looked carefully through 2 Ada reference books, one dedicated to tasking, and using Google to no end, I am stumped on the following Ada dilemma.
>
> generic
>
> type Managed_Task_Type is limited private;
>
> package WD is
Why not
generic
with function is_Terminated return Boolean;
package WD is
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Using the "Terminated" aspect for a task passed to a generic
2018-04-23 14:20 Using the "Terminated" aspect for a task passed to a generic NiGHTS
2018-04-23 15:40 ` AdaMagica
@ 2018-04-23 16:23 ` Jeffrey R. Carter
2018-04-23 16:29 ` Dmitry A. Kazakov
` (2 subsequent siblings)
4 siblings, 0 replies; 8+ messages in thread
From: Jeffrey R. Carter @ 2018-04-23 16:23 UTC (permalink / raw)
On 04/23/2018 04:20 PM, NiGHTS wrote:
>
> generic
>
> type Managed_Task_Type is limited private;
>
> package WD is
>
> task WD_Thread;
>
> end WD;
Ada doesn't have a generic formal task type. Within WD, the only operations you
have on the type are 'Address, 'Size, "in", and "not in". (I thinks that's it.
If I've forgotten some, they're similar in utility.) If you want to apply any
other operation, you have to require it as a generic formal subprogram:
generic
type Managed_Task is limited private;
with function Terminated (T : Managed_Task) return Boolean;
package WD is ...
--
Jeff Carter
"When danger reared its ugly head, he bravely
turned his tail and fled."
Monty Python and the Holy Grail
60
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Using the "Terminated" aspect for a task passed to a generic
2018-04-23 14:20 Using the "Terminated" aspect for a task passed to a generic NiGHTS
2018-04-23 15:40 ` AdaMagica
2018-04-23 16:23 ` Jeffrey R. Carter
@ 2018-04-23 16:29 ` Dmitry A. Kazakov
2018-04-23 16:35 ` Dan'l Miller
2018-04-23 17:18 ` NiGHTS
4 siblings, 0 replies; 8+ messages in thread
From: Dmitry A. Kazakov @ 2018-04-23 16:29 UTC (permalink / raw)
On 2018-04-23 16:20, NiGHTS wrote:
> Having looked carefully through 2 Ada reference books, one dedicated to tasking, and using Google to no end, I am stumped on the following Ada dilemma.
>
> generic
>
> type Managed_Task_Type is limited private;
I am not sure if that would work, but you could try your luck with
type Managed_Task_Type is
new Task_Type and task interface with private;
or
type Managed_Task_Type is
synchronized new Task_Type with private;
A better way, almost always, is to put the task into a tagged object and
pass that down:
task type Task_Type is ...
type Task_Object is
new Ada.Finalization.Limited_Controlled with
record
The_Task : Task_Type;
end record;
function Is_Terminated (Object : Task_Object) return Boolean is
begin
return Object.The_Task'Terminated;
end Is_Terminated;
generic
type Managed_Task_Type is new Task_Object with private;
package WD is
...
task body WD_Thread is
M : Managed_Task_Type;
begin
while not M.Is_Terminated loop
...
end loop;
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Using the "Terminated" aspect for a task passed to a generic
2018-04-23 14:20 Using the "Terminated" aspect for a task passed to a generic NiGHTS
` (2 preceding siblings ...)
2018-04-23 16:29 ` Dmitry A. Kazakov
@ 2018-04-23 16:35 ` Dan'l Miller
2018-04-23 16:41 ` Dmitry A. Kazakov
2018-04-23 17:04 ` Dan'l Miller
2018-04-23 17:18 ` NiGHTS
4 siblings, 2 replies; 8+ messages in thread
From: Dan'l Miller @ 2018-04-23 16:35 UTC (permalink / raw)
On Monday, April 23, 2018 at 9:20:33 AM UTC-5, NiGHTS wrote:
> Having looked carefully through 2 Ada reference books, one dedicated to tasking, and using Google to no end, I am stumped on the following Ada dilemma.
>
> generic
>
> type Managed_Task_Type is limited private;
Wait. Why can't we write:
generic
type Managed_Task_Type is limited task interface;
package WD is
...
as per 12.5.5's AI95-00345 example in the _AARM:2012TC1_ page 527 (given there without the “limited”)?
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Using the "Terminated" aspect for a task passed to a generic
2018-04-23 16:35 ` Dan'l Miller
@ 2018-04-23 16:41 ` Dmitry A. Kazakov
2018-04-23 17:04 ` Dan'l Miller
1 sibling, 0 replies; 8+ messages in thread
From: Dmitry A. Kazakov @ 2018-04-23 16:41 UTC (permalink / raw)
On 2018-04-23 18:35, Dan'l Miller wrote:
> On Monday, April 23, 2018 at 9:20:33 AM UTC-5, NiGHTS wrote:
>> Having looked carefully through 2 Ada reference books, one dedicated to tasking, and using Google to no end, I am stumped on the following Ada dilemma.
>>
>> generic
>>
>> type Managed_Task_Type is limited private;
>
> Wait. Why can't we write:
>
> generic
> type Managed_Task_Type is limited task interface;
> package WD is
> ...
>
> as per 12.5.5's AI95-00345 example in the _AARM:2012TC1_ page 527 (given there without the “limited”)?
Because you could not declare an object out of the interface, which
seems to be a requirement.
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Using the "Terminated" aspect for a task passed to a generic
2018-04-23 16:35 ` Dan'l Miller
2018-04-23 16:41 ` Dmitry A. Kazakov
@ 2018-04-23 17:04 ` Dan'l Miller
1 sibling, 0 replies; 8+ messages in thread
From: Dan'l Miller @ 2018-04-23 17:04 UTC (permalink / raw)
On Monday, April 23, 2018 at 11:35:11 AM UTC-5, Dan'l Miller wrote:
> On Monday, April 23, 2018 at 9:20:33 AM UTC-5, NiGHTS wrote:
> > generic
> >
> > type Managed_Task_Type is limited private;
>
> Wait. Why can't we write:
>
> generic
> type Managed_Task_Type is limited task interface;
> package WD is
> ...
>
> as per 12.5.5's AI95-00345 example in the _AARM:2012TC1_ page 527 (given there without the
> “limited”)?
Oh, as per _AARM:2012TC1_'s 3.9.4's Syntax paragraph 2/2, the syntax doesn't support the limited there because of the subsequent 5/2's “… all task and protected interfaces are synchronized interfaces, and all
synchronized interfaces are limited interfaces”. So amended, it would revert to aforementioned example:
Wait. Why can't OP modify the design to write:
generic
type Managed_Task_Type is task interface;
package WD is
... // then the OP's design adjusted to pass in the task-interfaced type instead of having the package
// contain a freshly-declared task.
as per 12.5.5's AI95-00345 example in the _AARM:2012TC1_ page 527?
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Using the "Terminated" aspect for a task passed to a generic
2018-04-23 14:20 Using the "Terminated" aspect for a task passed to a generic NiGHTS
` (3 preceding siblings ...)
2018-04-23 16:35 ` Dan'l Miller
@ 2018-04-23 17:18 ` NiGHTS
4 siblings, 0 replies; 8+ messages in thread
From: NiGHTS @ 2018-04-23 17:18 UTC (permalink / raw)
Thank you all for your help. These are some really interesting ideas.
I was thinking about my problem out-of-the-box and felt it would be an effective implementation to make a package including a task interface rather than a generic package passing a task. I realized that the task probably should not be defined separately from the WD package and should instead be part of the same inherited package.
To simplify code organization is in itself a bug fix.
I appreciate your quick responses and I have learned a few things as well. Thank you again!
^ permalink raw reply [flat|nested] 8+ messages in thread