comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Select then abort can fail to abort the abortable part
Date: Thu, 20 Nov 2014 22:35:27 +0100
Date: 2014-11-20T22:35:27+01:00	[thread overview]
Message-ID: <vwpncp0r5gp4$.1g6tt9l95v0zu$.dlg@40tude.net> (raw)
In-Reply-To: 546e5862$0$1628$426a34cc@news.free.fr

On 20 Nov 2014 21:08:50 GMT, Jean François Martinez wrote:

> Context:  Gnat x86_64 on Linux
> 
> 
> Let's have that simple loop
> 
> for Ind in 1..6
> loop
>     Start:=Clock;
>     select
>         delay Ind * 10.0
>     then abort 
>        Ultimate_Prime;
>     end select; 
>     My_Duration:= Clock - Start;
> end loop;
> 
> Ultimate_Prime is function containing a nearly infinite loop trying to 
> find prime numbers.  
> 
> First version stores primes found.  This mandates a linked list but that 
> would create an unacceptable overhead so I use big chunks
> 
>      type Big_Array is array (Positive range 1..100_000) of Long_Mod;
>      type Chunk is record
>           Position: Positive  range Big_Array'Range;
>           Payload: Big_Array;
>      end record;
>      type T_Ptr_Chunk is access  T;
> 
>      package P_List_Chunks is
>        new Ada.Containers.Doubly_Linked_Lists(T_Ptr_Chunk);

You certainly should not abort any code changing dynamically allocated
structures. I don't know the implementation of
Ada.Containers.Doubly_Linked_Lists, but it is not protected against abort
in the middle of changing list links, you may get garbage in the result.

You should almost never use the asynchronous transfer of control. A clean
method of aborting a lengthy computation is by inserting inspection points
within loops and raising an exception when abort was requested or time was
expired.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

  reply	other threads:[~2014-11-20 21:35 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-20 21:08 Select then abort can fail to abort the abortable part Jean François Martinez
2014-11-20 21:35 ` Dmitry A. Kazakov [this message]
2014-11-20 22:19   ` Jean François Martinez
2014-11-21  8:37     ` Dmitry A. Kazakov
2014-11-21 15:26       ` Jean François Martinez
2014-11-20 21:36 ` Adam Beneschan
2014-11-20 22:55   ` Jean François Martinez
replies disabled

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