ADA95 – part III Real-Time Systems Lecture 3 Copyright, 2002 © Adam Czajka.

Slides:



Advertisements
Similar presentations
© Alan Burns and Andy Wellings, 2001 MESSAGE-BASED SYNCHRONISATION AND COMMUNICATION Goals n To understand the requirements for communication and synchronisation.
Advertisements

Control Structures Ranga Rodrigo. Control Structures in Brief C++ or JavaEiffel if-elseif-elseif-else-end caseinspect for, while, do-whilefrom-until-loop-end.
Slide: 1 The Implementation of Ada 2005 Synchronized Interfaces in the GNAT Compiler Javier Miranda Hristian Kirtchev Edmond Schonberg Presentation cover.
Concurrency Important and difficult (Ada slides copied from Ed Schonberg)
Ch. 7 Process Synchronization (1/2) I Background F Producer - Consumer process :  Compiler, Assembler, Loader, · · · · · · F Bounded buffer.
Stored Procedure Language Stored Procedure Overview Stored Procedure is a function in a shared library accessible to the database server can also write.
From HRT-HOOD to ADA95 Real-Time Systems Lecture 5 Copyright, 2001 © Adam Czajka.
1 Chapter 8 Channels. 2 Concurrent Programming Constructs So far we have seen contructs based on shared memory concept (shared directly – buffer - or.
Distributed RT Systems ITV Real-Time Systems Anders P. Ravn Aalborg University February 2006.
Concurrency - 1 Exceptions General mechanism for handling abnormal conditions Predefined exceptions: constraint violations, I/O errors, communication errors,
Sequential Statements Module F3.2. Sequential Statements Statements executed sequentially within a process If Statements Case Statements Loop Statements.
Concurrency in Ada Programming Languages 1 Robert Dewar.
Concurrency in Ada What concurrency is all about Relation to operating systems Language facilities vs library packages POSIX threads Ada concurrency Real.
Concurrency - 1 Exceptions General mechanism for handling abnormal conditions Predefined exceptions: constraint violations, I/O errors, communication errors,
Concurrency - 1 Exceptions General mechanism for handling abnormal conditions Predefined exceptions: constraint violations, I/O errors, communication errors,
Real-Time Systems and Programming Languages © Alan Burns and Andy Wellings Chapter 8: Resource Control.
Even More Ada Constructs 9 Oct Today’s Constructs Generics Private types Child library units Tasking Pragmas Elaboration.
Concurrency - 1 Tasking Concurrent Programming Declaration, creation, activation, termination Synchronization and communication Time and delays conditional.
Concurrent computations n Concurrent units that executes in parallel n Physical parallelism n Logical parallelism n Parallel abstract machine n How does.
1 Chapter 9 Spaces with LINDA. 2 Linda Linda is an experimental programming concept unlike ADA or Occam which are fully developed production-quality languages.
ISBN Chapter 13 Concurrency. Copyright © 2009 Addison-Wesley. All rights reserved.1-2 Chapter 13 Topics Introduction Introduction to Subprogram-Level.
1 Chapter 13 © 2002 by Addison Wesley Longman, Inc Introduction - Concurrency can occur at four levels: 1. Machine instruction level 2. High-level.
HRT-HOOD Real-Time Systems Lecture 4 Copyright, 2002 © Adam Czajka.
12/1/98 COP 4020 Programming Languages Parallel Programming in Ada and Java Gregory A. Riccardi Department of Computer Science Florida State University.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
Chapter 13 Concurrency. Copyright © 2012 Addison-Wesley. All rights reserved.1-2 Introduction Concurrency can occur at four levels: –Machine instruction.
CS 355 – PROGRAMMING LANGUAGES Dr. X. 1-2 Chapter 13 Topics Introduction Introduction to Subprogram-Level Concurrency Semaphores Monitors Message Passing.
ICS 145B -- L. Bic1 Project: Process/Thread Synchronization Textbook: pages ICS 145B L. Bic.
1 Copyright © 1998 by Addison Wesley Longman, Inc. Chapter 12 Concurrency can occur at four levels: 1. Machine instruction level 2. High-level language.
ISBN Chapter 13 Concurrency. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.13-2 Chapter 13 Topics Introduction Introduction.
1 Programming Languages and the Software Production Process Informal Cardelli’s metrics of programming languages fitness to real-time applications: Economy.
1 Concurrency Architecture Types Tasks Synchronization –Semaphores –Monitors –Message Passing Concurrency in Ada Java Threads.
Control Structures CPS120: Introduction to Computer Science Lecture 5.
Using a simple Rendez-Vous mechanism in Java
ICS 313: Programming Language Theory Chapter 13: Concurrency.
Distributed Programming Concepts and Notations. Inter-process Communication Synchronous Messages Asynchronous Messages Select statement Remote procedure.
ISBN Chapter 13 Concurrency. Copyright © 2015 Pearson. All rights reserved.1-2 Chapter 13 Topics Introduction Introduction to Subprogram-Level.
ISBN Chapter 13 Concurrency. Copyright © 2009 Addison-Wesley. All rights reserved.1-2 Chapter 13 Topics Introduction Introduction to Subprogram-Level.
Chapter 12, Slide 1 Concurrency Motivation 1: Mutual Exclusion  John and Mary share a bank acc't  withdraw x = copy balance to local machine subtract.
Lecture 6: Monitors & Semaphores. Monitor Contains data and procedures needed to allocate shared resources Accessible only within the monitor No way for.
13-1 Chapter 13 Concurrency Topics Introduction Introduction to Subprogram-Level Concurrency Semaphores Monitors Message Passing Java Threads C# Threads.
Operating Systems Lecture Notes Synchronization Matthew Dailey Some material © Silberschatz, Galvin, and Gagne, 2002.
Chapter 13 Concurrency. Copyright © 2012 Addison-Wesley. All rights reserved.1-2 Chapter 13 Topics Introduction Introduction to Subprogram-Level Concurrency.
Ada Constructs Revisited 21 Oct Constructs to be Expanded Generics Tasking Elaboration.
C H A P T E R E L E V E N Concurrent Programming Programming Languages – Principles and Paradigms by Allen Tucker, Robert Noonan.
Operating Systems CMPSC 473 Signals, Introduction to mutual exclusion September 28, Lecture 9 Instructor: Bhuvan Urgaonkar.
Channels. Models for Communications Synchronous communications – E.g. Telephone call Asynchronous communications – E.g. .
CE Operating Systems Lecture 8 Process Scheduling continued and an introduction to process synchronisation.
Chapter 13 Concurrency. Corrected and improved by Assoc. Prof. Zeki Bayram, EMU, North Cyprus. Original Copyright © 2012 Addison-Wesley. All rights reserved1-2.
1 Module 3: Processes Reading: Chapter Next Module: –Inter-process Communication –Process Scheduling –Reading: Chapter 4.5, 6.1 – 6.3.
Chapter 13 Concurrency.
Chapter 3: Process Concept
Background on the need for Synchronization
“Language Mechanism for Synchronization”
Concurrency Motivation 1: Mutual Exclusion
Sequential Statements
Module 7a: Classic Synchronization
Chapter 13 Concurrency.
Chapter 13 Concurrency.
Subject : T0152 – Programming Language Concept
Chapter 13 Concurrency.
Chapter 13 Concurrency.
Chapter 13 Concurrency.
The structure of programming
Chapter 13 Concurrency.
Thinking procedurally
Chapter 13 Concurrency.
Chapter 13 Concurrency.
Chapter 13 Concurrency.
Presentation transcript:

ADA95 – part III Real-Time Systems Lecture 3 Copyright, 2002 © Adam Czajka

Contents Tasks Protected objects

Copyright, 2002 © Adam Czajka Tasks task type task_id [(quantifier)] is [entry id (parameters);] [private [entry id (parameters);]] end [task_id];

Copyright, 2002 © Adam Czajka Tasks task body task_id is declarations..... begin... instructions... [accept id (parameters);]... instructions... end [task_id];

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;

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;

Copyright, 2002 © Adam Czajka Tasks Communication is synchronous Communication is synchronous Communication is asymmetric (client  server) Communication is asymmetric (client  server) task_name.entry proc_name (parameters); Communication

Copyright, 2002 © Adam Czajka Tasks Communication 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; T.E1(5, a); T.E1(5, a);

Copyright, 2002 © Adam Czajka Tasks Priorities task type task_id (p : Any_Priority) is pragma Priority(p);... end task_id; T1 : task_id(10);

Copyright, 2002 © Adam Czajka Tasks Interaction : time server client1 client2 accept E1 server.E1(); in,inout end; out,inout

Copyright, 2002 © Adam Czajka Tasks Interaction : time server client1 client2 accept E1 server.E1(); in,inout end; out,inout

Copyright, 2002 © Adam Czajka Tasks Producer-Consumer : task Buffer is entry Get(X : out Integer); entry Put(X : in Integer); end Buffer; task type Producer; task type Consumer;

Copyright, 2002 © Adam Czajka Tasks Producer-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 is begin Buffer.Get(Elem);.... end Producer; task body Producer is begin.... Buffer.Put(Elem); end Producer;

Copyright, 2002 © Adam Czajka Tasks Selective waiting : select accept E1(parameters) do.... end E1; or accept E2(parameters) do.... end E2; end select;

Copyright, 2002 © Adam Czajka Tasks Selective waiting – example : task Server is entry E1(...); entry E2(...);.... entry E i (...); end Server;

Copyright, 2002 © Adam Czajka Tasks task body Server is begin loop select accept E1(...) do..... end E1; or accept E2(...) do..... end E2;..... end select; end loop; end Server; Selective waiting – example :

Copyright, 2002 © Adam Czajka Tasks Conditional 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;

Copyright, 2002 © Adam Czajka Tasks Conditional 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;....

Copyright, 2002 © Adam Czajka Tasks Conditional accept :.... or when counter accept Put(X : in Integer)do counter := counter + 1; tmp(counter) := X; end Put; end select; end loop; end Buffer; buf : Buffer(10); El : Integer; Buffer.Put(5);Buffer.Get(El);

Copyright, 2002 © Adam Czajka Tasks Wait instructions : delay time; delay until time; loop delay end loop; Problem !!!

Copyright, 2002 © Adam Czajka Tasks Wait instructions : next_time := tm_Start; loop delay next_time;.... next_time := next_time + tm_Slice; end loop; OK.

Copyright, 2002 © Adam Czajka Tasks Wait 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;

Copyright, 2002 © Adam Czajka Tasks Wait instructions : main_loop: loop..... select accept E1(...) do..... end; or delay wait_time;..... exit main_loop; end select; end loop main_loop;

Copyright, 2002 © Adam Czajka Tasks Building a server : server_loop: loop..... select accept E1(...) do..... end; else null; end select;... delay timeSlice; end loop server_loop;

Copyright, 2002 © Adam Czajka Tasks Finishing a task : task Server is entry E1(...);..... entry Finish; end Server;

Copyright, 2002 © Adam Czajka Tasks Finishing a task : task body Server is begin loop select accept E1(...) do..... end; or..... or accept Finish do exit; end select; end loop; end Server;

Copyright, 2002 © Adam Czajka Tasks Finishing a task : task body Server is begin loop select accept E1(...) do..... end; or..... or terminate; end select; end loop; end Server;

Copyright, 2002 © Adam Czajka Tasks Conditional communication with Server: select Server.E1(...);..... or delay wait_time;..... end select;

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

Copyright, 2002 © Adam Czajka Protected objects protected body obj_name is..... entry E1(...) when Condition is begin..... end E1;..... end obj_name; Only Entry subroutines can have barriers, i.e. when statements.

Copyright, 2002 © Adam Czajka Protected objects Locks : ActionsLock type procedure, entry modificationsRead/Write functionreadingRead

Copyright, 2002 © Adam Czajka Protected objects Locks : State Caller ReadRead/Write EntryNo ProcedureNo FunctionYesNo

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 :

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 :

Copyright, 2002 © Adam Czajka Protected objects buf1 : Buffer(200); El : Integer; buf1.Put(100); buf1.Get(El); Example :

Copyright, 2002 © Adam Czajka Summary Tasks Protected objects