comp.lang.ada
 help / color / mirror / Atom feed
From: "Robert I. Eachus" <rieachus@comcast.net>
Subject: Re: Advantages
Date: Sun, 04 Jul 2004 13:42:43 -0400
Date: 2004-07-04T13:42:43-04:00	[thread overview]
Message-ID: <OK2dndI7f7QJ3HXdRVn-vA@comcast.com> (raw)
In-Reply-To: <sa47jtse93b.fsf@snoopy.apana.org.au>

Brian May wrote:

> The implication of what you say is you can't have a deadlock in Ada
> across different packages, that will compile, if you use protected
> objects in this manner to access variables
> 
> Not true!

As others have already pointed out.  True.  The wording of the standard 
is subtle to allow for things like asynchronous I/O operations, or 
protected operations in the library distributed with the compiler that 
'know' about special properties of the target system.  Or more 
important, OS calls that are potentially blocking, but where the 
protected object is coded so that the call is only made when it cannot 
block.

As Randy says, the wording of the message from GNAT is not as clear as 
it could be:  "You blockhead! This program can deadlock!"

That message, of course, is not appropriate in some of the special cases 
where the user can tell that deadlock/Program_Error will never occur. 
And of course "can" not "will" in the message is correct--the compiler 
can't tell if the operations that will deadlock will be called--at least 
not at compile time.

Of course, if you are designing real-time systems, this is what you 
should care about.  The Ada compiler cannot tell you that your program 
will deadlock.  What it can tell you, by the absense of warnings, is 
that your program will not have any deadlocks directly involving 
protected objects.  There are similar rules elsewhere in the language 
involving tasks.

> I would imagine that there are other cases where the compiler can't
> warn you.

No, the compiler can always warn you.  Of course, if you want, you can 
use protected objects to implement P and V, then wrap potentially 
blocking actions inside the semaphores implemented that way.  But that 
is going out of your way to get back to the situation without Ada 
protected objects.

The intent in Ada really is that protected objects used correctly will 
not create deadlocks.  Used correctly of course, means among other 
things absent bounded errors.  If you want to encapsulate a potentially 
blocking operation in a protected object, that is what entries and entry 
barriers are for.  You either have an entry where the barrier condition 
is that the potentially blocking action inside the entry will not block, 
or you can use a requeue statement if you determine that the action will 
block.  Either way, the user of the abstraction can use a timed or 
conditional entry call, so that the caller will either not block, or not 
block for more than a predetermined time.

-- 

                                           Robert I. Eachus

"The flames kindled on the Fourth of July, 1776, have spread over too 
much of the globe to be extinguished by the feeble engines of despotism; 
on the contrary, they will consume these engines and all who work them." 
-- Thomas Jefferson, 1821




  parent reply	other threads:[~2004-07-04 17:42 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-06-27  7:04 Advantages Andrew Carroll
2004-06-27 15:16 ` Advantages Nick Roberts
2004-06-27 21:22   ` Advantages Pascal Obry
2004-06-28  0:51   ` Advantages Robert I. Eachus
2004-06-28  1:59     ` Advantages Brian May
2004-06-29  0:24       ` Advantages Randy Brukardt
2004-06-29  3:32         ` Advantages Hyman Rosen
2004-06-29 18:41           ` Advantages Randy Brukardt
2004-07-02  0:49             ` Advantages Brian May
2004-07-02  1:31               ` Advantages Jeffrey Carter
2004-07-02  9:13               ` Advantages Dmitry A. Kazakov
2004-07-02 12:27               ` Advantages Marin David Condic
2004-07-04 17:42       ` Robert I. Eachus [this message]
2004-06-28 12:08   ` Advantages Marin David Condic
2004-06-27 18:32 ` Advantages Jim Rogers
  -- strict thread matches above, loose matches on Subject: below --
2004-06-28  9:52 Advantages Lionel.DRAGHI
     [not found] <20040628005515.0A1E74C4160@lovelace.ada-france.org>
2004-06-28  6:23 ` Advantages Andrew Carroll
2004-06-28 14:44   ` Advantages Jacob Sparre Andersen
2004-07-04 18:11   ` Advantages Robert I. Eachus
2004-06-26  6:28 Advantages Andrew Carroll
2004-06-25 19:41 Advantages Andrew Carroll
     [not found] <20040624170516.B4DFC4C4110@lovelace.ada-france.org>
2004-06-25 12:24 ` Advantages Andrew Carroll
2004-06-25 12:22   ` Advantages Peter Amey
2004-06-26 20:43   ` Advantages Marin David Condic
replies disabled

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