comp.lang.ada
 help / color / mirror / Atom feed
From: Jeffrey Carter <spam.jrcarter.not@spam.not.acm.org>
Subject: Re: Timeouts in Ada
Date: Thu, 17 Jul 2014 12:27:15 -0700
Date: 2014-07-17T12:27:15-07:00	[thread overview]
Message-ID: <lq982j$t2c$3@dont-email.me> (raw)
In-Reply-To: <50bdb713-7ce1-411b-810b-9bdee1d26b7a@googlegroups.com>

On 07/16/2014 10:18 PM, NiGHTS wrote:
>
> Now as an Ada beginner with a strong background in C/Asm I interpret this
> example in the following way...
>
> 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.

You've had lots of good answers to this. I'm going to try to look at it a bit 
differently to see if that helps.

Ada's tasking features are high-level and biased towards safety. Things like 
mutexes are sort of like the machine code that Ada's tasking structures are 
implemented with, just as an if statement is implemented with conditional gotos. 
You shouldn't think in terms of conditional gotos, and you shouldn't think in 
terms of low-level concurrency primitives. In this case, your experience using 
low-level languages works against you.

Ada defines the effect of using its tasking features, not how that effect is 
obtained. You are asking about the latter. That is like asking how code is 
generated for an if statement. Unless you're a compiler writer, it's really not 
important, so long as you understand the effect of the if statement. And just as 
on this processor an if may be implemented using a BNE instruction, and on 
another with a JNZ, how Ada's tasking is implemented will vary based on the target.

Generally, between your code and the platform there will be an Ada run-time 
library (RTL). Your code will be translated into calls to the RTL.

If you're targeting bare metal, there will be nothing below the RTL. All tasking 
and scheduling will be done by the RTL.

If you're targeting an OS, generally the RTL will use OS services to implement 
tasking. Tasks will be mapped onto OS threads, delays onto timers, and so forth.

While an implementation might decide to create a thread or 2 as you suggest, 
it's unlikely. There's a task T that executes the select statement. Most likely 
T has the scheduler create a timer and queue the entry call, then blocks. 
Eventually something happens that causes the scheduler to make T runnable again, 
and some time after that the scheduler will run T again. Then T will look at the 
event that allowed it to run again and take one of the 2 branches based on that.

The important thing is that T waits for one of those 2 events (entry call going 
through or delay expiring) and then completes the corresponding branch of the 
select. How that is implemented is no more important than what machine code is 
generated for an if.

Finally, most of the answers talk about the delay being canceled when the entry 
call is accepted. Reality is more murky than that. The entry call can be 
accepted, then requeued "with abort", and the delay can still cancel the entry 
call, and the accept-requeue sequence can happen any number of times. Generally 
entry calls are "abort deferred", so if the call is accepted and is not 
currently requeued with abort, the call cannot be canceled. So a more complete 
answer may be, if the entry call has not been accepted, or has been accepted but 
is currently requeued with abort, then the time out will cancel the entry call. 
Otherwise the entry call will complete. I'm not clear about what happens if the 
entry call completes but the time out expires before it does, but I think in 
that case the select branch is completed and the or branch is ignored.

(Originally the semantics were defined in terms of the entry call being accepted 
because Ada 83 didn't have requeue. Ada 95 introduced requeue and things got murky.)

-- 
Jeff Carter
"You a big nose have it."
Never Give a Sucker an Even Break
107

      parent reply	other threads:[~2014-07-17 19:27 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
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 [this message]
replies disabled

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