comp.lang.ada
 help / color / mirror / Atom feed
* How to make a task wait and resume ?
@ 2019-01-17 16:21 reinert
  2019-01-17 17:28 ` Dmitry A. Kazakov
  0 siblings, 1 reply; 5+ messages in thread
From: reinert @ 2019-01-17 16:21 UTC (permalink / raw)


Hi there,

I have used a protected object to control (from "outside") 
wait/resume of a task. It works, but is it good practise?

Below is an illustration on what I mean. Hope you get it :-)

reinert  

   protected pause1 is
     entry wait1;
     procedure halt1;
     procedure resume1;
   private
     OK : boolean := false;
   end pause1;

   protected body pause1 is

     entry wait1 when OK is
     begin
        null;
     end wait1;

     procedure halt1 is
     begin
       OK := false;
     end halt1;

     procedure resume1 is
     begin
       OK := true;
     end resume1;
   end pause1;

   task body task1 is 
   begin
     loop
       pause1.wait1;
       do_something;
     end loop;
   end task1;


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: How to make a task wait and resume ?
  2019-01-17 16:21 How to make a task wait and resume ? reinert
@ 2019-01-17 17:28 ` Dmitry A. Kazakov
  2019-01-17 22:28   ` Randy Brukardt
  0 siblings, 1 reply; 5+ messages in thread
From: Dmitry A. Kazakov @ 2019-01-17 17:28 UTC (permalink / raw)


On 2019-01-17 17:21, reinert wrote:

> I have used a protected object to control (from "outside")
> wait/resume of a task. It works, but is it good practise?

Why not? In other cases you might use a task entry instead of protected 
object.

What you did is a manual reset event. For your case a pulse event might 
work better:

    entry wait1 when OK is
    begin
       OK := False;
    end wait1;

If the pulse event to release several tasks it is a bit more 
complicated. An example is in the Simple Components.

Then there is usually task exit condition involved. So the pattern might be:

    entry wait1 when OK or else Exit_Requested is
    begin
       if Exit_Requested then
          raise End_Error;
       else
          OK := False;
       end if;
    end wait1;

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: How to make a task wait and resume ?
  2019-01-17 17:28 ` Dmitry A. Kazakov
@ 2019-01-17 22:28   ` Randy Brukardt
  2019-01-18  7:59     ` reinert
  0 siblings, 1 reply; 5+ messages in thread
From: Randy Brukardt @ 2019-01-17 22:28 UTC (permalink / raw)



"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message 
news:q1qe0o$1te0$1@gioia.aioe.org...
> On 2019-01-17 17:21, reinert wrote:
>
>> I have used a protected object to control (from "outside")
>> wait/resume of a task. It works, but is it good practise?
>
> Why not? In other cases you might use a task entry instead of protected 
> object.

You could also use the built-in types for that purpose, see D.10, 
Synchronous Task Control.

...
> If the pulse event to release several tasks it is a bit more complicated. 
> An example is in the Simple Components.

 For that, you might want to use a Synchronous Barrier, see D.10.1.

For me, I would try to do this as part of other necessary synchronization, 
using usual task or protected operations. One rarely wants to have a task 
wait in a vacuum. If I had to do it by iteself, however, I'd probably use 
one of the built-in types (have to implement them in Janus/Ada, first, 
though :-).

                          Randy.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: How to make a task wait and resume ?
  2019-01-17 22:28   ` Randy Brukardt
@ 2019-01-18  7:59     ` reinert
  2019-01-18 10:20       ` Dmitry A. Kazakov
  0 siblings, 1 reply; 5+ messages in thread
From: reinert @ 2019-01-18  7:59 UTC (permalink / raw)


I suspected to be missing something :-)

In my case, a user is normally actively interacting with the actual program
which is about treating a large sequence of images. The user can start/stop 
a task which reads in images upfront to avoid waiting time. If the computer
is weak (small ram) he/she sometimes has to stop the reading (and the program automatically "clean" memory) and probably resume later. Hence the "synchronization" here is not with other tasks.

reinert

torsdag 17. januar 2019 23.28.17 UTC+1 skrev Randy Brukardt følgende:
> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message 
> news:q1qe0o$1te0$1@gioia.aioe.org...
> > On 2019-01-17 17:21, reinert wrote:
> >
> >> I have used a protected object to control (from "outside")
> >> wait/resume of a task. It works, but is it good practise?
> >
> > Why not? In other cases you might use a task entry instead of protected 
> > object.
> 
> You could also use the built-in types for that purpose, see D.10, 
> Synchronous Task Control.
> 
> ...
> > If the pulse event to release several tasks it is a bit more complicated. 
> > An example is in the Simple Components.
> 
>  For that, you might want to use a Synchronous Barrier, see D.10.1.
> 
> For me, I would try to do this as part of other necessary synchronization, 
> using usual task or protected operations. One rarely wants to have a task 
> wait in a vacuum. If I had to do it by iteself, however, I'd probably use 
> one of the built-in types (have to implement them in Janus/Ada, first, 
> though :-).
> 
>                           Randy.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: How to make a task wait and resume ?
  2019-01-18  7:59     ` reinert
@ 2019-01-18 10:20       ` Dmitry A. Kazakov
  0 siblings, 0 replies; 5+ messages in thread
From: Dmitry A. Kazakov @ 2019-01-18 10:20 UTC (permalink / raw)


On 2019-01-18 08:59, reinert wrote:
> I suspected to be missing something :-)
> 
> In my case, a user is normally actively interacting with the actual program
> which is about treating a large sequence of images. The user can start/stop
> a task which reads in images upfront to avoid waiting time. If the computer
> is weak (small ram) he/she sometimes has to stop the reading (and the program automatically "clean" memory) and probably resume later. Hence the "synchronization" here is not with other tasks.

This looks more like a classic Ada tasking (AKA monitors):

task body Reader is
    Buffer : Stream_Element_Array (1..Size);
    Last   : Stream_Element_Offset;
    File   : File_Type;
begin
    loop
      -- accept new file, open it
      begin
         loop
            Read (File.Stream, Buffer, Last);
            -- cache portion of file in Buffer (1..Last)
            select
               accept Forget_It;
               -- close file, clean up
               exit;
            else
               null;
            end select;
          end loop;
       exception
          when End_Error =>
             -- close file
    end loop;
end Reader;

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-01-18 10:20 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-17 16:21 How to make a task wait and resume ? reinert
2019-01-17 17:28 ` Dmitry A. Kazakov
2019-01-17 22:28   ` Randy Brukardt
2019-01-18  7:59     ` reinert
2019-01-18 10:20       ` Dmitry A. Kazakov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox