PDF de programación - Gestión del tiempo en Ada

Imágen de pdf Gestión del tiempo en Ada

Gestión del tiempo en Adagráfica de visualizaciones

Publicado el 14 de Mayo del 2019
509 visualizaciones desde el 14 de Mayo del 2019
209,8 KB
31 paginas
Creado hace 16a (22/10/2007)
ditdit

UPM

Gestión del tiempo en Ada

Juan Antonio de la Puente

DIT/UPM

El tiempo en Ada

 La gestión del tiempo en Ada está integrada en el

lenguaje y en el modelo de tareas

– relojes
– relojes de tiempo de ejecución
– retardos
– límites de tiempo

22/10/07

Gestiòn del tiempo en Ada

1

5
0
0
2
-
2
0
0
2
e
n
e
u
P
a



t

l


i



t

e
d
o
n
o
n
A
n
a
u
J

©



Relojes

En Ada hay dos paquetes predefinidos que proporcionan
funciones de reloj:

 Ada.Calendar

Duration

 Ada.Real_Time

5
0
0
2
-
2
0
0
2
e
n
e
u
P
a

t



l


i



t

e
d
o
n
o
n
A
n
a
u
J

©



– Define un tipo abstracto Time
– La función Clock da un valor de tiempo para uso externo
– Los intervalos de tiempo se representan con el tipo predefinido

– Define un tipo abstracto Time
– La función Clock da un valor monótono, sin saltos
– Los intervalos de tiempo se representan con el tipo abstracto

Time_Span

También hay relojes de tiempo de ejecución

22/10/07

Gestiòn del tiempo en Ada

Relojes en Ada-

2

Intervalos de tiempo

 El tipo Duration representa intervalos de tiempo en

segundos

 Es un tipo de coma fija:

type Duration is delta ... range ...;

– Su resolución, Duration’Small, no debe ser mayor que 20ms

(se recomienda que no sobrepase los 100µs)

– El intervalo de valores debe comprender ±1 día

(-86_400.0 .. +86_400.0)

22/10/07

Gestiòn del tiempo en Ada

Relojes en Ada-

3

5
0
0
2
-
2
0
0
2
e
n
e
u
P
a

t



l


i



t

e
d
o
n
o
n
A
n
a
u
J

©



Ada.Calendar (1)

package Ada.Calendar is

type Time is private;

subtype Year_Number
subtype Month_Number is Integer range 1..12;
subtype Day_Number
subtype Day_Duration

is Integer range 1..31;

is Duration range 0.0..86_400.0;

is Integer range 1901..2099;

function Clock return Time;

function Year (Date : Time) return Year_Number;
function Month (Date : Time) return Month_Number;
function Day (Date : Time) return Day_Number;
function Seconds(Date : Time) return Day_Duration;

procedure Split(Date : in Time;



Year : out Year_Number;
Month : out Month_Number;
Day : out Day_Number;
Seconds : out Day_Duration);



22/10/07

Gestiòn del tiempo en Ada

Relojes en Ada-

4

5
0
0
2
-
2
0
0
2
e
n
e
u
P
a

t



l


i



t

e
d
o
n
o
n
A
n
a
u
J

©



Ada.Calendar (2)

function Time_Of

(Year : Year_Number;
Month : Month_Number;
Day : Day_Number;
Seconds : Day_Duration := 0.0)
return Time;

function "+" (Left : Time; Right : Duration) return Time;

function "+" (Left : Duration; Right : Time) return Time;
function "-" (Left : Time; Right : Duration) return Time;
function "-" (Left : Time; Right : Time) return Duration;

function "<" (Left, Right : Time) return Boolean;
function "<=" (Left, Right : Time) return Boolean;
function ">" (Left, Right : Time) return Boolean;
function ">=" (Left, Right : Time) return Boolean;

Time_Error : exception;
end Ada.Calendar;

22/10/07

Gestiòn del tiempo en Ada

Relojes en Ada-

5

5
0
0
2
-
2
0
0
2
e
n
e
u
P
a

t



l


i



t

e
d
o
n
o
n
A
n
a
u
J

©



Comentarios a Ada.Calendar

 Los valores del tipo Time combinan la fecha y la hora

 La hora se da en segundos desde medianoche
– cuando hay un segundo intercalar se llega a 86_400.0

 El reloj se supone sincronizado con una referencia

externa (UTC o TO)
– los detalles se dejan para el entorno (SO)

 Los paquetes Ada.Calendar.Time_Zones

Ada.Calendar.Arithmetic y Ada.Calendar.Formatting
proporcionan funciones adicionales

22/10/07

Gestiòn del tiempo en Ada

Relojes en Ada-

6

5
0
0
2
-
2
0
0
2
e
n
e
u
P
a

t



l


i



t

e
d
o
n
o
n
A
n
a
u
J

©



Ada.Real_Time (1)

package Ada.Real_Time is
type Time is private;
Time_First : constant Time;
Time_Last : constant Time;
Time_Unit : constant := -- real number;
type Time_Span is private;
Time_Span_First : constant Time_Span;
Time_Span_Last : constant Time_Span;
Time_Span_Zero : constant Time_Span;
Time_Span_Unit : constant Time_Span;
Tick : constant Time_Span;
function Clock return Time;
function "+" (Left : Time; Right : Time_Span) return Time;
function "+" (Left : Time_Span; Right : Time) return Time;
function "-" (Left : Time; Right : Time_Span) return Time;
function "-" (Left : Time; Right : Time) return Time_Span;

function "<" (Left, Right : Time) return Boolean;
function "<=" (Left, Right : Time) return Boolean;
function ">" (Left, Right : Time) return Boolean;
function ">=" (Left, Right : Time) return Boolean;
22/10/07

Gestiòn del tiempo en Ada

Relojes en Ada-

7

5
0
0
2
-
2
0
0
2
e
n
e
u
P
a

t



l


i



t

e
d
o
n
o
n
A
n
a
u
J

©



Ada.Real_Time (2)

function "+" (Left, Right : Time_Span) return Time_Span;
function "-" (Left, Right : Time_Span) return Time_Span;
function "-" (Right : Time_Span) return Time_Span;
function "*" (Left : Time_Span; Right : Integer) return Time_Span;
function "*" (Left : Integer; Right : Time_Span)return Time_Span;
function "/" (Left, Right : Time_Span) return Integer;
function "/" (Left : Time_Span; Right : Integer) return Time_Span;
function "abs" (Right : Time_Span) return Time_Span;

function "<" (Left, Right : Time_Span) return Boolean;
function "<=" (Left, Right : Time_Span) return Boolean;
function ">" (Left, Right : Time_Span) return Boolean;
function ">=" (Left, Right : Time_Span) return Boolean;

function To_Duration (TS : Time_Span) return Duration;
function To_Time_Span (D : Duration) return Time_Span;

function Nanoseconds (NS : integer) return Time_Span;
function Microseconds (US : integer) return Time_Span;
function Milliseconds (MS : integer) return Time_Span;

22/10/07

Gestiòn del tiempo en Ada

Relojes en Ada-

8

5
0
0
2
-
2
0
0
2
e
n
e
u
P
a

t



l


i



t

e
d
o
n
o
n
A
n
a
u
J

©



Ada.Real_Time (3)

type Seconds_Count is new Integer range ...;

procedure Split (T : Time;

SC : out Seconds_Count;
TS : out Time_Span);

function Time_Of (SC : Seconds_Count; TS : Time_Span)

return Time;

end Ada.Real_Time;

22/10/07

Gestiòn del tiempo en Ada

Relojes en Ada-

9

5
0
0
2
-
2
0
0
2
e
n
e
u
P
a



t



l


i



t

e
d
o
n
o
n
A
n
a
u
J

©



Comentarios sobre Ada.Real_Time (1)

 El tipo Time representa valores de tiempo absolutos.
– Un valor T de tipo Time representa un intervalo de duración

[E + T ·Time_Unit, E + (T+1) · Time_Unit]

» Time_Unit no debe ser mayor de 20ms..
» El valor de E no está definido

– El intervalo de valores del tipo Time debe alcanzar al menos

50 años desde el arranque del sistema.

 El tipo Time_Span representa intervalos de tiempo.

– Un valor S de tipo Time_Span representa un intervalo de duración

igual a S · Time_Span_Unit .
» Time_Span_Unit =Time_Unit
» Duration’Small debe ser un múltiplo entero de Time_Span_Unit.

– El intervalo de valores del tipo Time_Span debe abarcar por lo

menos -3600..+3600 s .

22/10/07

Gestiòn del tiempo en Ada

Relojes en Ada-

10

5
0
0
2
-
2
0
0
2
e
n
e
u
P
a

t



l


i



t

e
d
o
n
o
n
A
n
a
u
J

©



Comentarios sobre Ada.Real_Time (2)

 La función Clock proporciona el tiempo absoluto

transcurrido desde la época.

 Tick es el valor medio del intervalo durante el cual el valor
de Clock permanece constante. No debe ser mayor de 1ms
– Se recomienda que el valor de Tick sea igual al de Time_Span_Unit,

o un múltiplo exacto de éste.

 El valor de Clock no debe disminuir en ningún momento (es

decir, el reloj es monótono no decreciente).

22/10/07

Gestiòn del tiempo en Ada

Relojes en Ada-

11

5
0
0
2
-
2
0
0
2
e
n
e
u
P
a



t

l


i

t



e
d
o
n
o
n
A
n
a
u
J

©



Ejemplo

declare


use Ada.Real_Time;
Start, Finish : Time;
Frame : Time_Span := Milliseconds(10);

begin
Start := Clock;
-- instrucciones
Finish := Clock;
if Finish - Start > Frame then
raise Time_Error;
-- excepción definida por el programador
end if;
end;

5
0
0
2
-
2
0
0
2
e
n
e
u
P
a



t

l


i

t



e
d
o
n
o
n
A
n
a
u
J

©



22/10/07

Gestiòn del tiempo en Ada

12

Retardo relativo

 La instrucción

delay expresión;

suspende la ejecución de la tarea que la invoca durante el
intervalo de tiempo que indica el valor de la expresión
– es de tipo Duration (y por tanto se mide en segundos)

 Una instrucción delay con argumento cero o negativo no

produce ningún retardo

22/10/07

Gestiòn del tiempo en Ada

13

5
0
0
2
-
2
0
0
2
e
n
e
u
P
a

t



l


i



t

e
d
o
n
o
n
A
n
a
u
J

©



Retardo absoluto

 La instrucción

delay until expresión;

suspende la ejecución de la tarea que la invoca hasta que
el valor del reloj sea igual al especificado por la expresión

 La expresión es de uno de estos tipos:

– Ada.Calendar.Time
– Ada.Real_Time.Time

 Se usa el reloj correspondiente al tipo Time utilizado
 Si se especifica un tiempo anterior al valor actual del reloj,

no se produce ningún retardo

22/10/07

Gestiòn del tiempo en Ada

14

5
0
0
2
-
2
0
0
2
e
n
e
u
P
a



t

l


i



t

e
d
o
n
o
n
A
n
a
u
J

©



Ejemplo: tarea periódica

use Ada.Real_Time;
task body Periodic is
Period : constant Time_Span := ...;
Next_Time : Time := ...;
begin
-- iniciación
loop
delay until Next_Time;
-- acción periódica
Next_Time := Next_Time + Period;
end loop;
end Periodic;

22/10/07

Gestiòn del tiempo en Ada

15

5
0
0
2
-
2
0
0
2
e
n
e
u
P
a



t

l


i



t

e
d
o
n
o
n
A
n
a
u
J

©



Limitación del tiempo de espera

 A menudo conviene limitar el tiempo durante el cual se

espera que ocurra un suceso

 Ejemplos:

– Acceso a una sección crítica:

La espera está limitada por la duración de la sección crítica

– Sincronización
  • Links de descarga
http://lwp-l.com/pdf15917

Comentarios de: Gestión del tiempo en Ada (0)


No hay comentarios
 

Comentar...

Nombre
Correo (no se visualiza en la web)
Valoración
Comentarios...
CerrarCerrar
CerrarCerrar
Cerrar

Tienes que ser un usuario registrado para poder insertar imágenes, archivos y/o videos.

Puedes registrarte o validarte desde aquí.

Codigo
Negrita
Subrayado
Tachado
Cursiva
Insertar enlace
Imagen externa
Emoticon
Tabular
Centrar
Titulo
Linea
Disminuir
Aumentar
Vista preliminar
sonreir
dientes
lengua
guiño
enfadado
confundido
llorar
avergonzado
sorprendido
triste
sol
estrella
jarra
camara
taza de cafe
email
beso
bombilla
amor
mal
bien
Es necesario revisar y aceptar las políticas de privacidad