From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: Timeouts in Ada Date: Thu, 17 Jul 2014 08:08:47 +0100 Organization: A noiseless patient Spider Message-ID: References: <50bdb713-7ce1-411b-810b-9bdee1d26b7a@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx05.eternal-september.org; posting-host="5cbec41b82bafb9ba55107f02585e18b"; logging-data="22322"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18cs0zNuiv4IdhM11Hrko3FoSdgk3BpYrg=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (darwin) Cancel-Lock: sha1:ZxNflEtidcYXQJktpMKCiL7CNfI= sha1:wgl7GWDxo6C7vcAhljtyllRemRs= Xref: news.eternal-september.org comp.lang.ada:20988 Date: 2014-07-17T08:08:47+01:00 List-Id: NiGHTS 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