comp.lang.ada
 help / color / mirror / Atom feed
From: Jeffrey Carter <spam@spam.com>
Subject: Re: Advantages
Date: Fri, 02 Jul 2004 01:31:14 GMT
Date: 2004-07-02T01:31:14+00:00	[thread overview]
Message-ID: <CV2Fc.1744$oD3.1632@newsread1.news.pas.earthlink.net> (raw)
In-Reply-To: <sa4k6xnutan.fsf@snoopy.apana.org.au>

Brian May wrote:

> You want to send a message to a hardware device. The requirements
> specify that one message should be sent to the device, followed by a
> fixed delay, then another message. During this entire period of time,
> exclusive access is required to the device, because other threads
> could otherwise interfere.
> 
> Lets also assume that sending the message is a blocking function that
> will block until either an acknowledgement or error is returned by the
> device.
> 
> What is the safest way of implementing this under Ada?
> 
> You could have a protected type emulate a semaphore, but then we are
> back to using primitive operations (and related mistakes) that Ada was
> meant to avoid.

The problem is that protected objects are not general-purposes 
structures to provide mutual exclusion, as they appear on the surface. 
Rather, they are specialized to provide mutual exclusion for data. Hence 
the restrictions against calling potentially blocking operations.

This was probably a mistake, but that changes nothing. If you're 
creating your own language, you can avoid making this mistake.

Probably the safest way is the Ada-83 way: use a task. Tasks can block 
all they want.

If the measured overhead of an additional task and a rendezvous exceeds 
your requirement, Ada has some features that allow a semaphore to be 
used much more safely than in other languages:

A controlled type can be used to automatically seize (during Initialize) 
and release (during Finalize) a semaphore. This avoids the omission of 
such calls, especially the "missed path" problem in which there is an 
exit path (such as due to exceptions) without a release call.

The semaphore can be hidden; those who invoke the sequence of operations 
see them as a single atomic operation. This localizes the places where 
the semaphore is manipulated, and makes finding errors in its use easier.

-- 
Jeff Carter
"I'm a lumberjack and I'm OK."
Monty Python's Flying Circus
54




  reply	other threads:[~2004-07-02  1:31 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               ` Jeffrey Carter [this message]
2004-07-02  9:13               ` Advantages Dmitry A. Kazakov
2004-07-02 12:27               ` Advantages Marin David Condic
2004-07-04 17:42       ` Advantages Robert I. Eachus
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