comp.lang.ada
 help / color / mirror / Atom feed
From: Simon Wright <simon@pushface.org>
Subject: Re: Timeouts in Ada
Date: Thu, 17 Jul 2014 08:08:47 +0100
Date: 2014-07-17T08:08:47+01:00	[thread overview]
Message-ID: <lyfvi0xy0w.fsf@pushface.org> (raw)
In-Reply-To: 50bdb713-7ce1-411b-810b-9bdee1d26b7a@googlegroups.com

NiGHTS <nights@unku.us> writes:

> 1. "select" creates a thread which runs the body of "select" or the
> body of "or". Or maybe it creates two threads for each and blocks its
> own thread until one finishes.

No, there are probably only 2 threads here; the one running the code
that executes the select, and the server task.

> 4. If the "select" body completes before the "or" body is completed,
> the "or" thread is terminated. If the "or" body completes before the
> "select" body completes, the "select" body and the Password_Server (if
> applicable) is terminated.

I don't see why the server task would be terminated?

> 5.a. If both threads happen to reach the "Put_Line" command of each
> body, both threads will terminate and there would be a conflict of
> information -- It will confuse the user with printing both "Done" AND
> "The system is busy". If this was a more mission-critical operation,
> both the main operation and its fallback plan may execute at the same
> time. In other words I don't see how this is atomic, and if its not
> atomic how could this possibly be useful to anyone?

There will be some complicated arrangment of condition variables (Unix),
semaphores (VxWorks), or other OS-dependent mechanisms to ensure that
the select statement runs as  required.

cond_timedwait(3) example from [1] - not very clear really, I admit:

       The cond_timedwait() function is normally used in a loop testing
       some condition.  It uses an absolute timeout value as follows:

	 timestruc_t to;
	 ...
	 (void) mutex_lock(mp);
	 to.tv_sec = time(NULL) + TIMEOUT;
	 to.tv_nsec = 0;
	 while (cond == FALSE) {
	       err = cond_timedwait(cvp, mp, &to);
	       if (err == ETIME) {
		     /* timeout, do something */
		     break;
	       }
	 }
	 (void) mutex_unlock(mp);

> Now keep in mind these are all assumptions I made in order to make
> sense of what I am reading. So far in my self-study of Ada 80% of
> everything had to be assumed with the help of trial and error because
> no literature that I have read explained WHY things happen, only
> superficial usage syntax.

You're actually asking HOW the compiler does it; ARM 9.7.1(15ff)[2] says
WHAT the compiler has to arrange to happen to meet the standard.

[1] http://www.unix.com/man-page/opensolaris/3c/cond_wait/
[2] http://www.ada-auth.org/standards/12rm/html/RM-9-7-1.html#p15

  reply	other threads:[~2014-07-17  7:08 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-17  5:18 Timeouts in Ada NiGHTS
2014-07-17  7:08 ` Simon Wright [this message]
2014-07-17  8:35   ` NiGHTS
2014-07-21 23:34   ` Randy Brukardt
2014-07-22  1:11     ` Shark8
2014-07-22  7:39       ` J-P. Rosen
2014-07-22  8:31         ` Simon Wright
2014-07-22 21:52       ` Randy Brukardt
2014-07-17  7:38 ` J-P. Rosen
2014-07-17  8:40   ` NiGHTS
2014-07-17 10:00     ` J-P. Rosen
2014-07-17 19:27   ` Jeffrey Carter
2014-07-17 19:51     ` J-P. Rosen
2014-07-17 20:52       ` Jeffrey Carter
2014-07-17 20:29     ` Adam Beneschan
2014-07-17 20:52       ` J-P. Rosen
2014-07-21 23:44         ` Randy Brukardt
2014-07-17 20:43     ` Jeffrey Carter
2014-07-21 23:37   ` Randy Brukardt
2014-07-17  7:42 ` Dmitry A. Kazakov
2014-07-17  8:59   ` NiGHTS
2014-07-17  9:48     ` Dmitry A. Kazakov
2014-07-17 17:10       ` NiGHTS
2014-07-17 20:45         ` Dmitry A. Kazakov
2014-07-17 16:12 ` Adam Beneschan
2014-07-17 16:46   ` NiGHTS
2014-07-17 17:11     ` Simon Wright
2014-07-17 17:58       ` NiGHTS
2014-07-17 19:02         ` Jeffrey Carter
2014-07-17 18:58       ` Jeffrey Carter
2014-07-17 18:12     ` Adam Beneschan
2014-07-17 19:27       ` Jeffrey Carter
2014-07-17 18:56     ` Jeffrey Carter
2014-07-23 22:37     ` Robert A Duff
2014-07-24  9:23       ` AdaMagica
2014-07-24 15:37         ` Robert A Duff
2014-07-25  5:16           ` Randy Brukardt
2014-07-25  9:11           ` AdaMagica
2014-07-25 16:15             ` Brad Moore
2014-07-25 16:34             ` Dmitry A. Kazakov
2014-07-17 19:27 ` Jeffrey Carter
replies disabled

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