comp.lang.ada
 help / color / mirror / Atom feed
* Need info about Ada tasks
@ 2008-09-25 13:31 Fionn Mac Cumhaill
  2008-09-25 13:49 ` Dmitry A. Kazakov
  2008-09-26 10:21 ` Stephen Leake
  0 siblings, 2 replies; 7+ messages in thread
From: Fionn Mac Cumhaill @ 2008-09-25 13:31 UTC (permalink / raw)


I've been using Ada for several years now, but I have not needed to do
anything with tasking. I have decided that I need to learn it, and
have a simple project for it, but I am finding comprehensible
information to hard to find. Cohen's book has a lot of information,
but I am finding it to be very dense reading, and a few examples would
be very useful.

What I need to do:

I am using the MingW Ada compiler and the GWindows packages on Windows
XP.

I am writing a simple program which observes a table in SQL Server
2000 and lists its rows to a visible screen display. I need a simple
task structure that can update the display periodically, with a
specified wait time between updates. I need to be able to abort the
display task at any time when the display is not being updated.

My simple solution has a minor problem; I have a select just after the
display routine that receives the abort message, but if the message
doesn't arrive on time I get another iteration of the loop before the
task aborts. How can I make this thing abort immediately, even when I
have a delay(60.0) to give a 1-minute delay between display refreshes?
I.e., how do I bail out in the middle of a delay?



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

* Re: Need info about Ada tasks
  2008-09-25 13:31 Need info about Ada tasks Fionn Mac Cumhaill
@ 2008-09-25 13:49 ` Dmitry A. Kazakov
  2008-09-26  5:06   ` Fionn Mac Cumhaill
  2008-09-26 10:21 ` Stephen Leake
  1 sibling, 1 reply; 7+ messages in thread
From: Dmitry A. Kazakov @ 2008-09-25 13:49 UTC (permalink / raw)


On Thu, 25 Sep 2008 13:31:27 GMT, Fionn Mac Cumhaill wrote:

> My simple solution has a minor problem; I have a select just after the
> display routine that receives the abort message, but if the message
> doesn't arrive on time I get another iteration of the loop before the
> task aborts. How can I make this thing abort immediately, even when I
> have a delay(60.0) to give a 1-minute delay between display refreshes?
> I.e., how do I bail out in the middle of a delay?

1. If the abort event is implemented as a protected object:

task body Refresh_Engine is
begin
   loop
      ... -- Refresh the display
      select -- Timed entry call
         Abort_Event.Wait;
         exit;
      or delay 60.0;
      end select;
   end loop;
end Refresh_Engine;

2. If the abort event is signaled by an entry call:

task body Refresh_Engine is
begin
   loop
      ... -- Refresh the display
      select -- Selective accept with a time out alternative
         accept Abort_Event;
         exit;
      or delay 60.0;
      end select;
   end loop;
end Refresh_Engine;

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



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

* Re: Need info about Ada tasks
  2008-09-25 13:49 ` Dmitry A. Kazakov
@ 2008-09-26  5:06   ` Fionn Mac Cumhaill
  0 siblings, 0 replies; 7+ messages in thread
From: Fionn Mac Cumhaill @ 2008-09-26  5:06 UTC (permalink / raw)


On Thu, 25 Sep 2008 15:49:28 +0200, "Dmitry A. Kazakov"
<mailbox@dmitry-kazakov.de> wrote:

>On Thu, 25 Sep 2008 13:31:27 GMT, Fionn Mac Cumhaill wrote:
>
>> My simple solution has a minor problem; I have a select just after the
>> display routine that receives the abort message, but if the message
>> doesn't arrive on time I get another iteration of the loop before the
>> task aborts. How can I make this thing abort immediately, even when I
>> have a delay(60.0) to give a 1-minute delay between display refreshes?
>> I.e., how do I bail out in the middle of a delay?
>
>1. If the abort event is implemented as a protected object:
>
>task body Refresh_Engine is
>begin
>   loop
>      ... -- Refresh the display
>      select -- Timed entry call
>         Abort_Event.Wait;
>         exit;
>      or delay 60.0;
>      end select;
>   end loop;
>end Refresh_Engine;
>
>2. If the abort event is signaled by an entry call:
>
>task body Refresh_Engine is
>begin
>   loop
>      ... -- Refresh the display
>      select -- Selective accept with a time out alternative
>         accept Abort_Event;
>         exit;
>      or delay 60.0;
>      end select;
>   end loop;
>end Refresh_Engine;

Many thanks - that was exactly what I needed to know.



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

* Re: Need info about Ada tasks
  2008-09-25 13:31 Need info about Ada tasks Fionn Mac Cumhaill
  2008-09-25 13:49 ` Dmitry A. Kazakov
@ 2008-09-26 10:21 ` Stephen Leake
  2008-09-26 12:46   ` Fionn Mac Cumhaill
  1 sibling, 1 reply; 7+ messages in thread
From: Stephen Leake @ 2008-09-26 10:21 UTC (permalink / raw)


Fionn Mac Cumhaill <invisible@hiding.from.spam> writes:

> I am using the MingW Ada compiler and the GWindows packages on Windows
> XP.
>
> I am writing a simple program which observes a table in SQL Server
> 2000 and lists its rows to a visible screen display. I need a simple
> task structure that can update the display periodically, with a
> specified wait time between updates. I need to be able to abort the
> display task at any time when the display is not being updated.

Mixing tasking and GUI events can be problematic; only one thread
can call GUI functions.

The canonical solution to your problem is to use a Win32 timer, and
update the display in the timer event handler function. 

Then "abort the display task" becomes "disable the timer".

Although Dmitry solved your immediate problem, it might be better to
use a different example problem to study tasking.

-- 
-- Stephe



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

* Re: Need info about Ada tasks
  2008-09-26 10:21 ` Stephen Leake
@ 2008-09-26 12:46   ` Fionn Mac Cumhaill
  2008-09-27  5:56     ` Randy Brukardt
  0 siblings, 1 reply; 7+ messages in thread
From: Fionn Mac Cumhaill @ 2008-09-26 12:46 UTC (permalink / raw)


On Fri, 26 Sep 2008 06:21:54 -0400, Stephen Leake
<stephen_leake@stephe-leake.org> wrote:

>Fionn Mac Cumhaill <invisible@hiding.from.spam> writes:
>
>> I am using the MingW Ada compiler and the GWindows packages on Windows
>> XP.
>>
>> I am writing a simple program which observes a table in SQL Server
>> 2000 and lists its rows to a visible screen display. I need a simple
>> task structure that can update the display periodically, with a
>> specified wait time between updates. I need to be able to abort the
>> display task at any time when the display is not being updated.
>
>Mixing tasking and GUI events can be problematic; only one thread
>can call GUI functions.
>
>The canonical solution to your problem is to use a Win32 timer, and
>update the display in the timer event handler function. 
>
>Then "abort the display task" becomes "disable the timer".
>
>Although Dmitry solved your immediate problem, it might be better to
>use a different example problem to study tasking.

Mixing tasking and GUI events does indeed cause problems. The very
first subroutine call in the task object which can cause a Gui event
does not return when called.



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

* Re: Need info about Ada tasks
  2008-09-26 12:46   ` Fionn Mac Cumhaill
@ 2008-09-27  5:56     ` Randy Brukardt
  2008-09-27  7:48       ` Dmitry A. Kazakov
  0 siblings, 1 reply; 7+ messages in thread
From: Randy Brukardt @ 2008-09-27  5:56 UTC (permalink / raw)


"Fionn Mac Cumhaill" <invisible@hiding.from.spam> wrote in message 
news:6vlpd4tho80qpm9vduvhggdeg3np867cvc@4ax.com...
> On Fri, 26 Sep 2008 06:21:54 -0400, Stephen Leake
> <stephen_leake@stephe-leake.org> wrote:
>
>>Fionn Mac Cumhaill <invisible@hiding.from.spam> writes:
>>
>>> I am using the MingW Ada compiler and the GWindows packages on Windows
>>> XP.
>>>
>>> I am writing a simple program which observes a table in SQL Server
>>> 2000 and lists its rows to a visible screen display. I need a simple
>>> task structure that can update the display periodically, with a
>>> specified wait time between updates. I need to be able to abort the
>>> display task at any time when the display is not being updated.
>>
>>Mixing tasking and GUI events can be problematic; only one thread
>>can call GUI functions.

That's not quite true, in that it's possible to use a binding that allows 
multi-task access. Claw was designed to do that (it ensures that Windows is 
happy by decoupling the underlying calls from your tasks). We indeed have 
several examples that do pretty much what you are trying to do here (having 
multiple tasks writing at once to different windows).

>>The canonical solution to your problem is to use a Win32 timer, and
>>update the display in the timer event handler function.
>>
>>Then "abort the display task" becomes "disable the timer".

If you're comfortable with writing event handlers, that works. But it also 
serializes everything.

>>Although Dmitry solved your immediate problem, it might be better to
>>use a different example problem to study tasking.
>
> Mixing tasking and GUI events does indeed cause problems. The very
> first subroutine call in the task object which can cause a Gui event
> does not return when called.

It probably would work fine with Claw. That what happens when you use a 
cheap knock-off like GWindows. ;-)

                      Randy.





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

* Re: Need info about Ada tasks
  2008-09-27  5:56     ` Randy Brukardt
@ 2008-09-27  7:48       ` Dmitry A. Kazakov
  0 siblings, 0 replies; 7+ messages in thread
From: Dmitry A. Kazakov @ 2008-09-27  7:48 UTC (permalink / raw)


On Sat, 27 Sep 2008 00:56:59 -0500, Randy Brukardt wrote:

> "Fionn Mac Cumhaill" <invisible@hiding.from.spam> wrote in message 
> news:6vlpd4tho80qpm9vduvhggdeg3np867cvc@4ax.com...
>> On Fri, 26 Sep 2008 06:21:54 -0400, Stephen Leake
>> <stephen_leake@stephe-leake.org> wrote:
>>
>>>Fionn Mac Cumhaill <invisible@hiding.from.spam> writes:
>>>
>>>> I am using the MingW Ada compiler and the GWindows packages on Windows
>>>> XP.
>>>>
>>>> I am writing a simple program which observes a table in SQL Server
>>>> 2000 and lists its rows to a visible screen display. I need a simple
>>>> task structure that can update the display periodically, with a
>>>> specified wait time between updates. I need to be able to abort the
>>>> display task at any time when the display is not being updated.
>>>
>>>Mixing tasking and GUI events can be problematic; only one thread
>>>can call GUI functions.
> 
> That's not quite true, in that it's possible to use a binding that allows 
> multi-task access. Claw was designed to do that (it ensures that Windows is 
> happy by decoupling the underlying calls from your tasks). We indeed have 
> several examples that do pretty much what you are trying to do here (having 
> multiple tasks writing at once to different windows).

An addition. It is not always possible to route all events through GUI
ones. For example, in our systems we have events at ms rate and faster. No
GUI could ever handle this. Our events change the system state
independently on rendering. Keyboard, mouse and other GUI events are
processed separately. This is the design OP asked for. It works quite well.

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



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

end of thread, other threads:[~2008-09-27  7:48 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-09-25 13:31 Need info about Ada tasks Fionn Mac Cumhaill
2008-09-25 13:49 ` Dmitry A. Kazakov
2008-09-26  5:06   ` Fionn Mac Cumhaill
2008-09-26 10:21 ` Stephen Leake
2008-09-26 12:46   ` Fionn Mac Cumhaill
2008-09-27  5:56     ` Randy Brukardt
2008-09-27  7:48       ` 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