comp.lang.ada
 help / color / mirror / Atom feed
* Abort of C-code in a asynchronous_select
@ 2001-12-04 14:00 Vincent Smeets
  2001-12-04 15:17 ` Thierry Lelegard
  0 siblings, 1 reply; 5+ messages in thread
From: Vincent Smeets @ 2001-12-04 14:00 UTC (permalink / raw)


Hallo,

I have a driver for reading and writing data written in C. The
C-routines are protected with a semaphores against being called by two
threads at the same time. The code can't be changed.

I want to call the blocking C-Driver.Read routine from Ada but must be
able to abort the call in case of an application state change. I was
thinking of the statements:

select
   State.Not_Active;
then abort
   C_Driver.Read (Data, Data_Last);
end select;

I am assuming that in case the Read-call is aborted, the semaphore in C
isn't freed because C doesn't know anything about the Ada-abort. Am I
correct and how can I do it better?

-- 
Vincent Smeets
SchlumbergerSema -
Competence Center Informatik GmbH 
Lohberg 10 - 49716 Meppen - Germany
tel:  +49 5931-805-461
fax:  +49 5931-805-175
mail: VSmeets@slb.com
web:  www.cci.de



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Abort of C-code in a asynchronous_select
  2001-12-04 14:00 Abort of C-code in a asynchronous_select Vincent Smeets
@ 2001-12-04 15:17 ` Thierry Lelegard
  2001-12-05  3:31   ` Robert Dewar
  2001-12-05  6:15   ` Vincent Smeets
  0 siblings, 2 replies; 5+ messages in thread
From: Thierry Lelegard @ 2001-12-04 15:17 UTC (permalink / raw)


> select
>    State.Not_Active;
> then abort
>    C_Driver.Read (Data, Data_Last);
> end select;
> 
> I am assuming that in case the Read-call is aborted, the semaphore in C
> isn't freed because C doesn't know anything about the Ada-abort. Am I
> correct and how can I do it better?

It entirely depends on the operating system and the implementation
of the Ada95 runtime. In your specific case, you can't even be sure
that the Read call is aborted. It may block until the read completes
(ie. the abort is ineffective).

ATC is extremely tricky. Generally speaking, it should be considered
safe only in specific cases such as compute-bound loops written in Ada.

When you try to abort non-Ada code (especially system services) using
ATC, you should check first with your Ada vendor in which cases this
will work.

Most Ada runtime libraries are implemented in user-mode on top of a
pthread (or pthread-like) system runtime. When a thread executes
inner-modes code (such as a device driver), there is simply no way
for a user-mode Ada runtime library to abort the call in a general
purpose manner.

As a programming rule, we have banned ATC in our developement teams. Full stop.
-Thierry
____________________________________________________________________________

Thierry Lelegard, "The Jazzing Troll", Email: thierry.lelegard@canal-plus.fr
CANAL+ Technologies, 34 place Raoul Dautry, 75906 Paris Cedex 15, France
Tel: +33 1 71 71 54 30   Fax: +33 1 71 71 52 08   Mobile: +33 6 03 00 65 75
____________________________________________________________________________



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Abort of C-code in a asynchronous_select
  2001-12-04 15:17 ` Thierry Lelegard
@ 2001-12-05  3:31   ` Robert Dewar
  2001-12-05  6:15   ` Vincent Smeets
  1 sibling, 0 replies; 5+ messages in thread
From: Robert Dewar @ 2001-12-05  3:31 UTC (permalink / raw)


Thierry Lelegard <thierry.lelegard@canal-plus.fr> wrote in message news:<3C0CE8F1.31F74C6@canal-plus.fr>...
> As a programming rule, we have banned ATC in our 
> developement teams. Full stop.

Good idea :-)

Note that you can enforce this with pragma Restrictions,
and if you also enforce avoiding the use of abort, you may
well find your runtime can behave more efficiently!



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Abort of C-code in a asynchronous_select
  2001-12-04 15:17 ` Thierry Lelegard
  2001-12-05  3:31   ` Robert Dewar
@ 2001-12-05  6:15   ` Vincent Smeets
  2001-12-05  8:59     ` Thierry Lelegard
  1 sibling, 1 reply; 5+ messages in thread
From: Vincent Smeets @ 2001-12-05  6:15 UTC (permalink / raw)


Thierry Lelegard wrote:
> 
> > select
> >    State.Not_Active;
> > then abort
> >    C_Driver.Read (Data, Data_Last);
> > end select;
> >
> > I am assuming that in case the Read-call is aborted, the semaphore in C
> > isn't freed because C doesn't know anything about the Ada-abort. Am I
> > correct and how can I do it better?
> 
> It entirely depends on the operating system and the implementation
> of the Ada95 runtime. In your specific case, you can't even be sure
> that the Read call is aborted. It may block until the read completes
> (ie. the abort is ineffective).

Thanks,

I have redisgned it already for not using an ATC. I was thinking myself
of it as a too great risk of being system-dependent.

As a note: I am using GNAT 3.13p on Solaris 2.6 and the C_Driver.Read
routine isn't directly a Solaris driver but an emulation of an
driver/device written in C with sockets. Later the Ada software shall
run on an embedded system with pSOS+.


-- 
Vincent Smeets
SchlumbergerSema -
Competence Center Informatik GmbH 
Lohberg 10 - 49716 Meppen - Germany
tel:  +49 5931-805-461
fax:  +49 5931-805-175
mail: VSmeets@slb.com
web:  www.cci.de



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Abort of C-code in a asynchronous_select
  2001-12-05  6:15   ` Vincent Smeets
@ 2001-12-05  8:59     ` Thierry Lelegard
  0 siblings, 0 replies; 5+ messages in thread
From: Thierry Lelegard @ 2001-12-05  8:59 UTC (permalink / raw)


Vincent Smeets wrote:

> As a note: I am using GNAT 3.13p on Solaris 2.6 and the C_Driver.Read
> routine isn't directly a Solaris driver but an emulation of an
> driver/device written in C with sockets. Later the Ada software shall
> run on an embedded system with pSOS+.

Precisely, when the abort is made, your C code is likely into a socket
"read", that is to say you are into a system service / device driver:
the TCP/IP driver! I would guess that ATC will not work at all in this case.

-Thierry
____________________________________________________________________________

Thierry Lelegard, "The Jazzing Troll", Email: thierry.lelegard@canal-plus.fr
CANAL+ Technologies, 34 place Raoul Dautry, 75906 Paris Cedex 15, France
Tel: +33 1 71 71 54 30   Fax: +33 1 71 71 52 08   Mobile: +33 6 03 00 65 75
____________________________________________________________________________



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2001-12-05  8:59 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-12-04 14:00 Abort of C-code in a asynchronous_select Vincent Smeets
2001-12-04 15:17 ` Thierry Lelegard
2001-12-05  3:31   ` Robert Dewar
2001-12-05  6:15   ` Vincent Smeets
2001-12-05  8:59     ` Thierry Lelegard

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