From: "Jean François Martinez" <darkquark99@gmail.com>
Subject: Select then abort can fail to abort the abortable part
Date: 20 Nov 2014 21:08:50 GMT
Date: 2014-11-20T22:08:50+01:00 [thread overview]
Message-ID: <546e5862$0$1628$426a34cc@news.free.fr> (raw)
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);
use P_List_Chunks;
List_Chunks: List;
So this first version is "dumb": it tries every odd number until
Divisor * Divisor > Candidate. If it is a prime it is stored in the
Payload array though an access variable ie _without_ even looking at the
List. The List is only accessed for concatenating a new Chunk.
Now when I run it I notice that the select then abort can take over 1
second or even two seconds more than the delay and the number of
Primes found is ever a multiple of 100_000 ie the function was only
aborted when it entered code provided by AdaCore in order to allocate a
new Chunk and to add a new element to the List.
The second version is "smart". It only tries to divide by prime numbers.
This means we have to use the numbers previously stored in our list so
for An_Element in List_Chunks
loop
for Ind in 1..Position
loop
In this version we are constantly traversing List_Chunks and using
Adacore's code. Here the function is aborted very close after the
expiration of the delay (from memory 0.05 at most after expiration) and
the number of prime numbers found is not a multiple of 100_000.
Third version is tries very odd number as divisor but stores only the
last prime found. Ie no lists, no nothing. Just user code, nothing from
the run time or AdaCore's libraries. In this version the delay expires
but the there is no abort _at all_. Function will run until it leaves
voluntarily in, according my estimations, something like five hundred
thousand years.
Is this incorrect behavior?
---
Jean-François Martinez
next reply other threads:[~2014-11-20 21:08 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-20 21:08 Jean François Martinez [this message]
2014-11-20 21:35 ` Select then abort can fail to abort the abortable part Dmitry A. Kazakov
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