ADA95 – part III [email protected] Real-Time Systems Lecture 3 Copyright, 2002 © Adam...
-
Upload
sylvia-sullivan -
Category
Documents
-
view
215 -
download
0
Transcript of ADA95 – part III [email protected] Real-Time Systems Lecture 3 Copyright, 2002 © Adam...
![Page 1: ADA95 – part III Adam.Czajka@cs.put.poznan.pl Real-Time Systems Lecture 3 Copyright, 2002 © Adam Czajka.](https://reader035.fdocuments.us/reader035/viewer/2022062519/5697bfef1a28abf838cba0ce/html5/thumbnails/1.jpg)
ADA95 – part III ADA95 – part III
Real-Time SystemsReal-Time Systems
Lecture 3Lecture 3
Copyright, 2002 © Adam Czajka
![Page 2: ADA95 – part III Adam.Czajka@cs.put.poznan.pl Real-Time Systems Lecture 3 Copyright, 2002 © Adam Czajka.](https://reader035.fdocuments.us/reader035/viewer/2022062519/5697bfef1a28abf838cba0ce/html5/thumbnails/2.jpg)
Copyright, 2002 © Adam Czajka
Contents
Tasks
Protected objects
![Page 3: ADA95 – part III Adam.Czajka@cs.put.poznan.pl Real-Time Systems Lecture 3 Copyright, 2002 © Adam Czajka.](https://reader035.fdocuments.us/reader035/viewer/2022062519/5697bfef1a28abf838cba0ce/html5/thumbnails/3.jpg)
Copyright, 2002 © Adam Czajka
Tasks
task type task_id [(quantifier)] is
[entry id (parameters);]
[private
[entry id (parameters);]]
end [task_id];
![Page 4: ADA95 – part III Adam.Czajka@cs.put.poznan.pl Real-Time Systems Lecture 3 Copyright, 2002 © Adam Czajka.](https://reader035.fdocuments.us/reader035/viewer/2022062519/5697bfef1a28abf838cba0ce/html5/thumbnails/4.jpg)
Copyright, 2002 © Adam Czajka
Tasks
task body task_id is
declarations .....
begin
... instructions ...
[accept id (parameters);]
... instructions ...
end [task_id];
![Page 5: ADA95 – part III Adam.Czajka@cs.put.poznan.pl Real-Time Systems Lecture 3 Copyright, 2002 © Adam Czajka.](https://reader035.fdocuments.us/reader035/viewer/2022062519/5697bfef1a28abf838cba0ce/html5/thumbnails/5.jpg)
Copyright, 2002 © Adam Czajka
Tasks
task type TP1(P : integer) is
entry E1(x: integer);
entry E2();
end TP1;
task type TP2(P : integer) is
entry E1();
end TP2;
![Page 6: ADA95 – part III Adam.Czajka@cs.put.poznan.pl Real-Time Systems Lecture 3 Copyright, 2002 © Adam Czajka.](https://reader035.fdocuments.us/reader035/viewer/2022062519/5697bfef1a28abf838cba0ce/html5/thumbnails/6.jpg)
Copyright, 2002 © Adam Czajka
Tasks
T1 : TP1(3);
T2 : TP2;
T3 : array (1..5) of T2;
type p_T1 is access T1;
type p_T2 is access T2;
p1 : p_T1 := new T1(3);
p2 : p_T2 := new T2;
![Page 7: ADA95 – part III Adam.Czajka@cs.put.poznan.pl Real-Time Systems Lecture 3 Copyright, 2002 © Adam Czajka.](https://reader035.fdocuments.us/reader035/viewer/2022062519/5697bfef1a28abf838cba0ce/html5/thumbnails/7.jpg)
Copyright, 2002 © Adam Czajka
Tasks
Communication is synchronousCommunication is synchronous
Communication is asymmetric Communication is asymmetric
(client (client server) server)
task_name.entry proc_name (parameters);
Communication
![Page 8: ADA95 – part III Adam.Czajka@cs.put.poznan.pl Real-Time Systems Lecture 3 Copyright, 2002 © Adam Czajka.](https://reader035.fdocuments.us/reader035/viewer/2022062519/5697bfef1a28abf838cba0ce/html5/thumbnails/8.jpg)
Copyright, 2002 © Adam Czajka
TasksCommunication
task type T is entry E1(x : in Integer; y : out Integer); end T; task body T is
... accept E1(x : in Integer; y : out Integer) do ... end E1;
... end T;
a : Integer;a : Integer; T.E1(5, a);T.E1(5, a);
![Page 9: ADA95 – part III Adam.Czajka@cs.put.poznan.pl Real-Time Systems Lecture 3 Copyright, 2002 © Adam Czajka.](https://reader035.fdocuments.us/reader035/viewer/2022062519/5697bfef1a28abf838cba0ce/html5/thumbnails/9.jpg)
Copyright, 2002 © Adam Czajka
TasksPriorities
task type task_id (p : Any_Priority) is pragma Priority(p); ... end task_id; T1 : task_id(10);
![Page 10: ADA95 – part III Adam.Czajka@cs.put.poznan.pl Real-Time Systems Lecture 3 Copyright, 2002 © Adam Czajka.](https://reader035.fdocuments.us/reader035/viewer/2022062519/5697bfef1a28abf838cba0ce/html5/thumbnails/10.jpg)
Copyright, 2002 © Adam Czajka
TasksInteraction :
time server client1 client2
accept E1
server.E1(); in,inout
end;out,inout
![Page 11: ADA95 – part III Adam.Czajka@cs.put.poznan.pl Real-Time Systems Lecture 3 Copyright, 2002 © Adam Czajka.](https://reader035.fdocuments.us/reader035/viewer/2022062519/5697bfef1a28abf838cba0ce/html5/thumbnails/11.jpg)
Copyright, 2002 © Adam Czajka
TasksInteraction :
time server client1 client2
accept E1
server.E1();
in,inout
end;out,inout
![Page 12: ADA95 – part III Adam.Czajka@cs.put.poznan.pl Real-Time Systems Lecture 3 Copyright, 2002 © Adam Czajka.](https://reader035.fdocuments.us/reader035/viewer/2022062519/5697bfef1a28abf838cba0ce/html5/thumbnails/12.jpg)
Copyright, 2002 © Adam Czajka
TasksProducer-Consumer :
task Buffer is entry Get(X : out Integer); entry Put(X : in Integer);end Buffer;
task type Producer;
task type Consumer;
![Page 13: ADA95 – part III Adam.Czajka@cs.put.poznan.pl Real-Time Systems Lecture 3 Copyright, 2002 © Adam Czajka.](https://reader035.fdocuments.us/reader035/viewer/2022062519/5697bfef1a28abf838cba0ce/html5/thumbnails/13.jpg)
Copyright, 2002 © Adam Czajka
TasksProducer-Consumer :
task body Buffer is Tmp : Integer;begin loop accept Get(X : out Integer) do X := Tmp; end; accept Put(X : in Integer) do Tmp := X; end; end loop;end Buffer;
task body Consumer isbegin Buffer.Get(Elem); ....end Producer;
task body Producer isbegin .... Buffer.Put(Elem);end Producer;
![Page 14: ADA95 – part III Adam.Czajka@cs.put.poznan.pl Real-Time Systems Lecture 3 Copyright, 2002 © Adam Czajka.](https://reader035.fdocuments.us/reader035/viewer/2022062519/5697bfef1a28abf838cba0ce/html5/thumbnails/14.jpg)
Copyright, 2002 © Adam Czajka
TasksSelective waiting :
select accept E1(parameters) do .... end E1; or accept E2(parameters) do .... end E2;end select;
![Page 15: ADA95 – part III Adam.Czajka@cs.put.poznan.pl Real-Time Systems Lecture 3 Copyright, 2002 © Adam Czajka.](https://reader035.fdocuments.us/reader035/viewer/2022062519/5697bfef1a28abf838cba0ce/html5/thumbnails/15.jpg)
Copyright, 2002 © Adam Czajka
TasksSelective waiting – example :
task Server is entry E1(...); entry E2(...); .... entry Ei(...);end Server;
![Page 16: ADA95 – part III Adam.Czajka@cs.put.poznan.pl Real-Time Systems Lecture 3 Copyright, 2002 © Adam Czajka.](https://reader035.fdocuments.us/reader035/viewer/2022062519/5697bfef1a28abf838cba0ce/html5/thumbnails/16.jpg)
Copyright, 2002 © Adam Czajka
Tasks
task body Server isbegin loop select accept E1(...) do ..... end E1; or accept E2(...) do ..... end E2; ..... end select; end loop;end Server;
Selective waiting – example :
![Page 17: ADA95 – part III Adam.Czajka@cs.put.poznan.pl Real-Time Systems Lecture 3 Copyright, 2002 © Adam Czajka.](https://reader035.fdocuments.us/reader035/viewer/2022062519/5697bfef1a28abf838cba0ce/html5/thumbnails/17.jpg)
Copyright, 2002 © Adam Czajka
TasksConditional accept :
when condition => accept E1(...) do ..... end E1;
task type Buffer(Size: Integer) is entry Get(X : out Integer); entry Put(X : in Integer);end Buffer;
![Page 18: ADA95 – part III Adam.Czajka@cs.put.poznan.pl Real-Time Systems Lecture 3 Copyright, 2002 © Adam Czajka.](https://reader035.fdocuments.us/reader035/viewer/2022062519/5697bfef1a28abf838cba0ce/html5/thumbnails/18.jpg)
Copyright, 2002 © Adam Czajka
TasksConditional accept :
task body Buffer(Size : Integer) is counter : Integer; tmp : array (1..Size) of Integer;begin loop select when counter > 0 => accept Get(X : out Integer)do X := tmp(counter); counter := counter – 1; end Get; ....
![Page 19: ADA95 – part III Adam.Czajka@cs.put.poznan.pl Real-Time Systems Lecture 3 Copyright, 2002 © Adam Czajka.](https://reader035.fdocuments.us/reader035/viewer/2022062519/5697bfef1a28abf838cba0ce/html5/thumbnails/19.jpg)
Copyright, 2002 © Adam Czajka
TasksConditional accept :
.... or when counter < Size => accept Put(X : in Integer)do counter := counter + 1; tmp(counter) := X; end Put; end select; end loop;end Buffer;
buf : Buffer(10);buf : Buffer(10);El : Integer;El : Integer; Buffer.Put(5);Buffer.Put(5);Buffer.Get(El);Buffer.Get(El);
![Page 20: ADA95 – part III Adam.Czajka@cs.put.poznan.pl Real-Time Systems Lecture 3 Copyright, 2002 © Adam Czajka.](https://reader035.fdocuments.us/reader035/viewer/2022062519/5697bfef1a28abf838cba0ce/html5/thumbnails/20.jpg)
Copyright, 2002 © Adam Czajka
TasksWait instructions :
delay time; delay until time;
loop
delay 3.0
....
end loop;
Problem !!!Problem !!!
![Page 21: ADA95 – part III Adam.Czajka@cs.put.poznan.pl Real-Time Systems Lecture 3 Copyright, 2002 © Adam Czajka.](https://reader035.fdocuments.us/reader035/viewer/2022062519/5697bfef1a28abf838cba0ce/html5/thumbnails/21.jpg)
Copyright, 2002 © Adam Czajka
TasksWait instructions :
next_time := tm_Start;
loop
delay next_time;
....
next_time := next_time + tm_Slice;
end loop;
OK.OK.
![Page 22: ADA95 – part III Adam.Czajka@cs.put.poznan.pl Real-Time Systems Lecture 3 Copyright, 2002 © Adam Czajka.](https://reader035.fdocuments.us/reader035/viewer/2022062519/5697bfef1a28abf838cba0ce/html5/thumbnails/22.jpg)
Copyright, 2002 © Adam Czajka
TasksWait instructions :
declare use Ada.Calendar; period : constant duration := 3.0; next_time : Time := starting_time;begin loop delay until next_time; .... next_time := next_time + period; end loop;end;
![Page 23: ADA95 – part III Adam.Czajka@cs.put.poznan.pl Real-Time Systems Lecture 3 Copyright, 2002 © Adam Czajka.](https://reader035.fdocuments.us/reader035/viewer/2022062519/5697bfef1a28abf838cba0ce/html5/thumbnails/23.jpg)
Copyright, 2002 © Adam Czajka
TasksWait instructions :
main_loop:loop ..... select accept E1(...) do ..... end; or delay wait_time; ..... exit main_loop; end select;end loop main_loop;
![Page 24: ADA95 – part III Adam.Czajka@cs.put.poznan.pl Real-Time Systems Lecture 3 Copyright, 2002 © Adam Czajka.](https://reader035.fdocuments.us/reader035/viewer/2022062519/5697bfef1a28abf838cba0ce/html5/thumbnails/24.jpg)
Copyright, 2002 © Adam Czajka
TasksBuilding a server :
server_loop:loop ..... select accept E1(...) do ..... end; else null; end select;...delay timeSlice;end loop server_loop;
![Page 25: ADA95 – part III Adam.Czajka@cs.put.poznan.pl Real-Time Systems Lecture 3 Copyright, 2002 © Adam Czajka.](https://reader035.fdocuments.us/reader035/viewer/2022062519/5697bfef1a28abf838cba0ce/html5/thumbnails/25.jpg)
Copyright, 2002 © Adam Czajka
TasksFinishing a task :
task Server is entry E1(...); ..... entry Finish;end Server;
![Page 26: ADA95 – part III Adam.Czajka@cs.put.poznan.pl Real-Time Systems Lecture 3 Copyright, 2002 © Adam Czajka.](https://reader035.fdocuments.us/reader035/viewer/2022062519/5697bfef1a28abf838cba0ce/html5/thumbnails/26.jpg)
Copyright, 2002 © Adam Czajka
TasksFinishing a task :task body Server isbegin loop select accept E1(...) do ..... end; or ..... or accept Finish do exit; end select; end loop;end Server;
![Page 27: ADA95 – part III Adam.Czajka@cs.put.poznan.pl Real-Time Systems Lecture 3 Copyright, 2002 © Adam Czajka.](https://reader035.fdocuments.us/reader035/viewer/2022062519/5697bfef1a28abf838cba0ce/html5/thumbnails/27.jpg)
Copyright, 2002 © Adam Czajka
TasksFinishing a task :task body Server isbegin loop select accept E1(...) do ..... end; or ..... or terminate;
end select; end loop;end Server;
![Page 28: ADA95 – part III Adam.Czajka@cs.put.poznan.pl Real-Time Systems Lecture 3 Copyright, 2002 © Adam Czajka.](https://reader035.fdocuments.us/reader035/viewer/2022062519/5697bfef1a28abf838cba0ce/html5/thumbnails/28.jpg)
Copyright, 2002 © Adam Czajka
TasksConditional communication
with Server:
select Server.E1(...); ..... or delay wait_time; .....end select;
![Page 29: ADA95 – part III Adam.Czajka@cs.put.poznan.pl Real-Time Systems Lecture 3 Copyright, 2002 © Adam Czajka.](https://reader035.fdocuments.us/reader035/viewer/2022062519/5697bfef1a28abf838cba0ce/html5/thumbnails/29.jpg)
Copyright, 2002 © Adam Czajka
protected type obj_name [ (quantifier) ] is entry E1(...); procedure P1(...); function F1(...); .....[private declarations_of_shared_variables procedure P2(...);]end obj_name;
Protected objects
![Page 30: ADA95 – part III Adam.Czajka@cs.put.poznan.pl Real-Time Systems Lecture 3 Copyright, 2002 © Adam Czajka.](https://reader035.fdocuments.us/reader035/viewer/2022062519/5697bfef1a28abf838cba0ce/html5/thumbnails/30.jpg)
Copyright, 2002 © Adam Czajka
Protected objects
protected body obj_name is..... entry E1(...) when Condition is begin ..... end E1;.....end obj_name;
Only Only EntryEntry subroutines can have barriers, i.e. subroutines can have barriers, i.e.
whenwhen statements. statements.
![Page 31: ADA95 – part III Adam.Czajka@cs.put.poznan.pl Real-Time Systems Lecture 3 Copyright, 2002 © Adam Czajka.](https://reader035.fdocuments.us/reader035/viewer/2022062519/5697bfef1a28abf838cba0ce/html5/thumbnails/31.jpg)
Copyright, 2002 © Adam Czajka
Protected objectsLocks :
Actions Lock type
procedure, entry
modifications Read/Write
function reading Read
![Page 32: ADA95 – part III Adam.Czajka@cs.put.poznan.pl Real-Time Systems Lecture 3 Copyright, 2002 © Adam Czajka.](https://reader035.fdocuments.us/reader035/viewer/2022062519/5697bfef1a28abf838cba0ce/html5/thumbnails/32.jpg)
Copyright, 2002 © Adam Czajka
Protected objectsLocks :
State
Caller
Read Read/Write
Entry No No
Procedure No No
Function Yes No
![Page 33: ADA95 – part III Adam.Czajka@cs.put.poznan.pl Real-Time Systems Lecture 3 Copyright, 2002 © Adam Czajka.](https://reader035.fdocuments.us/reader035/viewer/2022062519/5697bfef1a28abf838cba0ce/html5/thumbnails/33.jpg)
Copyright, 2002 © Adam Czajka
Protected objects
protected type Buffer(Size : Integer := 100) is entry Put(X : in Integer); entry Get(X : out Integer);private buf : array(1..N) of Integer counter : Integer range 0..N := 0;end Buffer;
Example :
![Page 34: ADA95 – part III Adam.Czajka@cs.put.poznan.pl Real-Time Systems Lecture 3 Copyright, 2002 © Adam Czajka.](https://reader035.fdocuments.us/reader035/viewer/2022062519/5697bfef1a28abf838cba0ce/html5/thumbnails/34.jpg)
Copyright, 2002 © Adam Czajka
Protected objects
protected body Buffer is entry Put(X : in Integer) when counter < N is begin counter := counter + 1; buf(counter) := X; end Put; entry Get(X : out Integer) when counter > 0 is begin X := buf(counter); counter := counter – 1; end Get;
end Buffer;
Example :
![Page 35: ADA95 – part III Adam.Czajka@cs.put.poznan.pl Real-Time Systems Lecture 3 Copyright, 2002 © Adam Czajka.](https://reader035.fdocuments.us/reader035/viewer/2022062519/5697bfef1a28abf838cba0ce/html5/thumbnails/35.jpg)
Copyright, 2002 © Adam Czajka
Protected objects
buf1 : Buffer(200);El : Integer; buf1.Put(100);buf1.Get(El);
Example :
![Page 36: ADA95 – part III Adam.Czajka@cs.put.poznan.pl Real-Time Systems Lecture 3 Copyright, 2002 © Adam Czajka.](https://reader035.fdocuments.us/reader035/viewer/2022062519/5697bfef1a28abf838cba0ce/html5/thumbnails/36.jpg)
Copyright, 2002 © Adam Czajka
SummarySummary
Tasks
Protected objects