Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

is there a 'wait' command in Ada

1,371 views
Skip to first unread message

tmo...@bix.com

unread,
Nov 29, 1996, 3:00:00 AM11/29/96
to

>What I mean is that; if I want a particular text to appear after,
>lets say, 10 seconds. What command do I use.
delay 10.0;

Robert A Duff

unread,
Nov 29, 1996, 3:00:00 AM11/29/96
to

In article <Pine.SOL.3.91.961129204410.12801A-100000@sirius>,
***** LOTUS ***** <nt...@herts.ac.uk> wrote:
>I've just started using Ada.. and want to know if there is a 'wait' command
>in Ada. What I mean is that; if I want a particular text to appear after,
>lets say, 10 seconds. What command do I use.

delay 10.0;
Put_Line("particular text");

There's also "delay until".

- Bob

***** LOTUS *****

unread,
Nov 29, 1996, 3:00:00 AM11/29/96
to

hi!

I've just started using Ada.. and want to know if there is a 'wait' command
in Ada. What I mean is that; if I want a particular text to appear after,
lets say, 10 seconds. What command do I use.

Thankyou

n.th...@herts.ac.uk


Michael Feldman

unread,
Nov 30, 1996, 3:00:00 AM11/30/96
to

In article <Pine.SOL.3.91.961129204410.12801A-100000@sirius>,
***** LOTUS ***** <nt...@herts.ac.uk> wrote:
>hi!
>
>I've just started using Ada.. and want to know if there is a 'wait' command
>in Ada. What I mean is that; if I want a particular text to appear after,
>lets say, 10 seconds. What command do I use.
>
delay 1.0;

will usually work. Compiler? Platform? Sometimes the behavior is a
bit unexpected, so more info will help us to help you.

Mike Feldman
------------------------------------------------------------------------
Michael B. Feldman - chair, SIGAda Education Working Group
Professor, Dept. of Electrical Engineering and Computer Science
The George Washington University - Washington, DC 20052 USA
202-994-5919 (voice) - 202-994-0227 (fax)
http://www.seas.gwu.edu/faculty/mfeldman
------------------------------------------------------------------------
Pork is all that money the government gives the other guys.
------------------------------------------------------------------------
WWW: http://www.adahome.com or http://info.acm.org/sigada/education
------------------------------------------------------------------------

Robert Dewar

unread,
Nov 30, 1996, 3:00:00 AM11/30/96
to

michael feldman says

"delay 1.0;

will usually work. Compiler? Platform? Sometimes the behavior is a
bit unexpected, so more info will help us to help you."


I don't get it, delay 1.0 must work on any implementation of Ada, what
do you have in mind here Mike?


Michael Feldman

unread,
Dec 1, 1996, 3:00:00 AM12/1/96
to

OK, you asked for it...:-)

One would think that a simple delay followed by a Put would be platform-
independently portable, but in this case the devil turns out to be in
the details.:-)

The delay will work, of course, but the poster's question was "how
do I pause my program before displaying a message?" Exactly when the
output will appear may be surprising. Sometimes a Flush is needed to
force it to the screen, for example.

Moreover, when running GNAT under GDB, including any tasking stuff
causes surprising behavior (or no behavior at all), and delay is
part of the tasking stuff in GNAT, etc., etc.

I was quite interested by this question. Some (including Robert)
have asserted that using delay just to pause an interactive program
was not a very interesting idea. Evidently others think otherwise.

I've argued that delay is a useful statement, completely independent of
its RM introduction in the tasking chapter. Indeed, my book is crazy
enough to use delay in several examples as a "pause" statement. This
has turned out to be a bit of a thorn in my students' sides, because
at GW, our intro courses run everything under GDB, which is hidden in
a script to produce a nice traceback on an unhandled exception.

GNAT, for better or worse, links in delay - even a simple delay in a
non-tasking program - as part of the tasking runtime. Because of the
unfriendly relations between tasking and GDB, programs that use
simple delays don't work under our scripts. We've ended up writing
a package called Sleep_Package, which exports a procedure Sleep
that just uses a simple Unix sleep call. That works fine, but the
students scratch their heads about why they have to change their code
because the Ada in the book doesn't behave as advertised.

Well, Robert, you asked the question, so I had to answer it.:-)

Mike Feldman

Robert Dewar

unread,
Dec 1, 1996, 3:00:00 AM12/1/96
to

Mike said

"GNAT, for better or worse, links in delay - even a simple delay in a
non-tasking program - as part of the tasking runtime. Because of the
unfriendly relations between tasking and GDB, programs that use
simple delays don't work under our scripts. We've ended up writing
a package called Sleep_Package, which exports a procedure Sleep
that just uses a simple Unix sleep call. That works fine, but the
students scratch their heads about why they have to change their code
because the Ada in the book doesn't behave as advertised.

Well, Robert, you asked the question, so I had to answer it.:-)"

Ah ha! "don't work under our scripts", so just possibly this is a Feldman
scriopt issue and not a fundamental Ada issue :-)


David C. Hoos, Sr.

unread,
Dec 2, 1996, 3:00:00 AM12/2/96
to

Hi Mike,
Have you ever thought of using the UNIX select function to implement a
"delay that doesn't burn CPU cycles or issue s shell command?
All you need to do is set all three of the file descriptor mask addresses
to null addresses, and point to a timeval structure initialized with the
desired delay time, and the UNIX kernel will swap you out until the time
has expired. Works like a champ!
--
David C. Hoos, Sr.,
http://www.dbhwww.com
http://www.ada95.com

Michael Feldman <mfel...@seas.gwu.edu> wrote in article
<57smdo$9...@felix.seas.gwu.edu>...


> In article <dewar.849411873@merv>, Robert Dewar <de...@merv.cs.nyu.edu>
wrote:
> >michael feldman says

> OK, you asked for it...:-)

Larry Kilgallen

unread,
Dec 2, 1996, 3:00:00 AM12/2/96
to

Sounds to me like a debugger issue.

Larry Kilgallen

Corey Minyard

unread,
Dec 2, 1996, 3:00:00 AM12/2/96
to

kilg...@eisner.decus.org (Larry Kilgallen) writes:

This has bugged me since I started using GNAT. If you use a delay,
you get a multi-threaded application. There is no way around it that
I have found. It is not a debugger issue (although a multi-threaded
debugger would be useful). There are other side-effects, too. Under
Linux, if you add a delay you will no longer be able to stop your
application with a ^C.

The delay could just call usleep or select to do its job (which should
work under threads), but instead it uses the thread package sleep
routines. There is probably a reason for this, but it is rather
inconvenient.

--
Corey Minyard Internet: min...@metronet.com
Work: min...@nortel.ca UUCP: min...@wf-rch.cirr.com
--
Corey Minyard Internet: min...@metronet.com
Work: min...@nortel.ca UUCP: min...@wf-rch.cirr.com

Michael Feldman

unread,
Dec 2, 1996, 3:00:00 AM12/2/96
to

In article <dewar.849498825@merv>, Robert Dewar <de...@merv.cs.nyu.edu> wrote:
>Mike said

>
>Ah ha! "don't work under our scripts", so just possibly this is a Feldman
>scriopt issue and not a fundamental Ada issue :-)
>
Well, the problem manifests itself in our script situation, but the
scripts are not the cause of the problem.

I never said any of this was a fundamental Ada issue. I _did_ say (and
did mean) that the behavior is sometimes surprising.

In running GNAT under GDB, things like simple delays do not behave as
expected (try it). And a simple delay, followed by a simple Put, does
NOT always display the message after exactly that amount of time.
Things like IO buffering give unexpected results.

These are neither bugs nor fundamental Ada issues, rather implementation
issues, but they bite nonetheless. They especially bite people who are
trying to move over from other languages and to understand just what the
RM means.

The original question was NOT "what is the Ada equivalent of pause", but
"how do I get my program to pause for 5 seconds, then display a message
on the screen". The answer "the delay statement" gives a partial answer only.

I stand by my answer, "the delay statement is part way to a solution, but
unless we know the platform and compiler, we can't say for sure."

Robert (or anyone else), if this is so easily and portably done (including
under a debugger like GDB), please post a short program illustrating it.
My answer was neither idle nor completely uninformed, but you may have a
solution I didn't think of. Instead of joking around, write a complete
little program that compiles and (portably) shows the desired behavior.

I stand by the second part of the answer too, which is "GNAT should not be
hauling tasking code into a program that does only a simple delay but
no tasking." This is an implementation decision that causes lots of
needlesss grief to those trying to debug simple sequential programs.
Maybe it will be fixed someday.

Mike Feldman

Larry Kilgallen

unread,
Dec 3, 1996, 3:00:00 AM12/3/96
to

In article <m2hgm4v...@metronet.com>, Corey Minyard <min...@metronet.com> writes:

> This has bugged me since I started using GNAT. If you use a delay,
> you get a multi-threaded application. There is no way around it that
> I have found. It is not a debugger issue (although a multi-threaded
> debugger would be useful).

If the debugger in question cannot deal with threads, that still
seems to me to be a debugger issue. I thought I read from Mike's
comment that a correct program would run alright unless the
debugger is introduced.

Larry Kilgallen

Robert A Duff

unread,
Dec 3, 1996, 3:00:00 AM12/3/96
to

In article <m2hgm4v...@metronet.com>,
Corey Minyard <min...@metronet.com> wrote:
>...Under

>Linux, if you add a delay you will no longer be able to stop your
>application with a ^C.

Why is that? Is that a bug in Linux, or a bug in the GNAT RTS?

- Bob

Corey Minyard

unread,
Dec 3, 1996, 3:00:00 AM12/3/96
to

I'm not saying that the lack of a threaded-aware debugger is ok when
debugging multi-threaded programs. I'm saying that requiring a
threaded-aware debugger to debug a program that is not multi-threaded
is a problem.

IMHO, the GNAT compiler should only require threads if using tasks.
Since delay is not implicitly an operation requiring threads, it
shouldn't require them.

I wrote an Ada application to send pages to my alphanumeric pager. It
used delay to time operations for retrying them. My wife (for whom
the program was written :-) was very annoyed that she could not ^C the
program (due to it using pthreads). So, I modified GNAT to use
linuxthreads (a kernel posix thread package) which works better in
that respect. I would have preferred to not have to do that. But now
I can do System V shared semaphores in a multi-task application
without locking up the whole process, which is something else I
needed.

Michael Feldman

unread,
Dec 3, 1996, 3:00:00 AM12/3/96
to

In article <1996Dec3.072025.1@eisner>,
Larry Kilgallen <kilg...@eisner.decus.org> wrote:

>If the debugger in question cannot deal with threads, that still
>seems to me to be a debugger issue. I thought I read from Mike's
>comment that a correct program would run alright unless the
>debugger is introduced.

Yes, that's true. So what? How should one debug a program that uses a
simple delay? A program that behaves funny under the debugger
behaves funny. Recall that I answered the original question by
saying "the behavior may be surprising." I stand by that statement.:-)

Actually, I've been messing with GDB on Solaris to see if there's a
workaround. It turns out that SIGWAITING is raised, apparently,
whenever a delay or whatever is encountered in the program. On
Solaris at least, typing, at the gdb command prompt,

handle SIGWAITING nostop
handle SIGWAITING noprint

seems to work. I haven't tried this (yet) on other platforms.

In any event, this is not the least bit obvious to a non-GDB expert.

Mike Feldman

Michael Feldman

unread,
Dec 3, 1996, 3:00:00 AM12/3/96
to

In article <m2hgm4v...@metronet.com>,
Corey Minyard <min...@metronet.com> wrote:

>This has bugged me since I started using GNAT. If you use a delay,
>you get a multi-threaded application. There is no way around it that
>I have found. It is not a debugger issue (although a multi-threaded

>debugger would be useful). There are other side-effects, too. Under

>Linux, if you add a delay you will no longer be able to stop your
>application with a ^C.

The ctrl-C problem has plagued many GNAT ports; it's been fixed in
Solaris, DOS, OS/2, and Mac, and my guess is that whoever knows the
Linux runtime could fix it there too. You might want to report it to
rep...@gnat.com and see what response you get.

>The delay could just call usleep or select to do its job (which should
>work under threads), but instead it uses the thread package sleep
>routines. There is probably a reason for this, but it is rather
>inconvenient.

I'd just like to see something a bit smarter in gnatlink (I guess that's
where it would be written) that notices whether or not any other tasking
stuff is needed, and if only simple delays are present, links a simple
call to an ordinary sleep.

This has come up before; like so many other things, finding a solution
is just a matter of focusing on it and giving it some priority. As I
understand it, ACT has its hands full, so hasn't focused much on this.
They've also opined, at times, that it's uncommon to use a simple delay
to pause a program, so other things get priority on their to-do list.

Mike Feldman

Larry Kilgallen

unread,
Dec 4, 1996, 3:00:00 AM12/4/96
to

In article <583052$1...@felix.seas.gwu.edu>, mfel...@seas.gwu.edu (Michael Feldman) writes:
> In article <1996Dec3.072025.1@eisner>,
> Larry Kilgallen <kilg...@eisner.decus.org> wrote:
>
>>If the debugger in question cannot deal with threads, that still
>>seems to me to be a debugger issue. I thought I read from Mike's
>>comment that a correct program would run alright unless the
>>debugger is introduced.
>
> Yes, that's true. So what? How should one debug a program that uses a
> simple delay? A program that behaves funny under the debugger
> behaves funny. Recall that I answered the original question by
> saying "the behavior may be surprising." I stand by that statement.:-)

Yes, exactly.

When I paraphrased your comment about the debugger involvement
I intended to emphasize that the problem is not due to "Mike's
funny padded room for students" but rather due to "the debugger",
an environment where one should be able to expect operation to be
identical to regular operation except for specially documented
debugging _features_.

In a non-Ada VMS environment I keep running into well-intentioned
individuals who want to rebuild a large program compiled /nooptimize
for general debugging of reported problems. They just don't value
having an exact byte-for-byte match with what the end user runs,
including any optimizer decisions. To me the whole value of a
debugger is in being able to reproduce the _exact_ circumstances
of a problem, although most that I have encountered cannot get
the area beyond the end of the stack to match the non-debugger
environment exactly :-).

Larry Kilgallen

Robert Dewar

unread,
Dec 4, 1996, 3:00:00 AM12/4/96
to

I have no trouble using GDB with programs that have delays in them. Works
fine on several targets that I tried. I am aware of the problem Mike has
with his automatic scripts, but if there are more general problems in
using GDB with any of the standard GNAT ports, they should be reported
to rep...@gnat.com as usual.

Robert Dewar


Keith Thompson

unread,
Dec 4, 1996, 3:00:00 AM12/4/96
to

In <m2bucby...@metronet.com> Corey Minyard <min...@metronet.com> writes:
[...]

> IMHO, the GNAT compiler should only require threads if using tasks.
> Since delay is not implicitly an operation requiring threads, it
> shouldn't require them.

But delay statements do affect task scheduling, and there's no way
to determine, when a delay statement is compiled, whether it will be
executed by a program with multiple tasks.

Making delay statements behave differently depending on whether the
program has multiple tasks is an interesting and doable optimization,
but it's not necessarily a trivial one.

--
Keith Thompson (The_Other_Keith) k...@aonix.com <http://www.aonix.com> <*>
TeleSo^H^H^H^H^H^H Alsy^H^H^H^H Thomson Softw^H^H^H^H^H^H^H^H^H^H^H^H^H Aonix
10251 Vista Sorrento Parkway, Suite 300, San Diego, CA, USA, 92121-2706
"SPOON!" -- The Tick

Fergus Henderson

unread,
Dec 9, 1996, 3:00:00 AM12/9/96
to

"David C. Hoos, Sr." <david.c...@ada95.com> writes:

>Have you ever thought of using the UNIX select function to implement a
>"delay that doesn't burn CPU cycles or issue s shell command?
>All you need to do is set all three of the file descriptor mask addresses
>to null addresses, and point to a timeval structure initialized with the
>desired delay time, and the UNIX kernel will swap you out until the time
>has expired. Works like a champ!

That works OK in a single-task program, but in a multitasking
program, the UNIX kernel may swap out the whole _process_ rather
than just delaying the individual task.

--
Fergus Henderson <f...@cs.mu.oz.au> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger f...@128.250.37.3 | -- the last words of T. S. Garp.

Robert I. Eachus

unread,
Dec 10, 1996, 3:00:00 AM12/10/96
to

"David C. Hoos, Sr." <david.c...@ada95.com> writes:

>Have you ever thought of using the UNIX select function to implement a
>"delay that doesn't burn CPU cycles or issue s shell command?
>All you need to do is set all three of the file descriptor mask addresses
>to null addresses, and point to a timeval structure initialized with the
>desired delay time, and the UNIX kernel will swap you out until the time
>has expired. Works like a champ!

It looks like what everyone is looking for is an implementation of
delay with the effective logic:

if Number_of_Tasks = 1
then Unix.Sleep(N)
else Ada.Runtime.Delay(N);
end if;

(I plan on general prinicples to ignore any discussion of the
"extra overhead" in doing things this way. If you execute a delay
statement you should only complain if it doesn't take as long as
requested, and a busy wait is an appropriate implementation for very
short delays.)

Also it should be the case that a runtime which supports pragma
Restrictions(Max_Tasks => 0) should not load the tasking runtime, even
if this requires special support for (more efficient) protected types.

--

Robert I. Eachus

with Standard_Disclaimer;
use Standard_Disclaimer;
function Message (Text: in Clever_Ideas) return Better_Ideas is...

0 new messages