Specification. Implementation

Similar documents
Real-Time Systems. Lecture #4. Professor Jan Jonsson. Department of Computer Science and Engineering Chalmers University of Technology

Process Management And Synchronization

Chapter 6: Process Synchronization. Operating System Concepts 9 th Edit9on

Resource management. Real-Time Systems. Resource management. Resource management

CHAPTER 6: PROCESS SYNCHRONIZATION

Semaphore. Originally called P() and V() wait (S) { while S <= 0 ; // no-op S--; } signal (S) { S++; }

A simple example... Introduction to Ada95. Literals. Identifiers

Different kinds of resources provided by a package

Chapter 7: Process Synchronization!

Comp2310 & Comp6310 Systems, Networks and Concurrency

Synchronization. Peter J. Denning CS471/CS571. Copyright 2001, by Peter Denning

Comp2310 & Comp6310 Systems, Networks and Concurrency

Parallel and Concurrent Programming

System Software. Computer Science and Engineering College of Engineering The Ohio State University. Lecture 13

Synchronization. Race Condition. The Critical-Section Problem Solution. The Synchronization Problem. Typical Process P i. Peterson s Solution

Process Synchronization

Synchronization Principles

1. Motivation (Race Condition)

Chapter 5: Process Synchronization. Operating System Concepts 9 th Edition

Interprocess Communication By: Kaushik Vaghani

Real-Time Programming

Process Synchronization

Operating Systems. Designed and Presented by Dr. Ayman Elshenawy Elsefy

CS370 Operating Systems

Chapter 6: Process Synchronization

EI 338: Computer Systems Engineering (Operating Systems & Computer Architecture)

Today s topic: Real Time Programming with Ada

Lecture Topics. Announcements. Today: Concurrency (Stallings, chapter , 5.7) Next: Exam #1. Self-Study Exercise #5. Project #3 (due 9/28)

Concurrency: Mutual Exclusion and Synchronization. Concurrency

Chapter 5: Process Synchronization. Operating System Concepts Essentials 2 nd Edition

Concurrent Programming

Chapter 6: Synchronization. Operating System Concepts 8 th Edition,

CS370: System Architecture & Software [Fall 2014] Dept. Of Computer Science, Colorado State University

Class Notes, 3/21/07, Operating Systems

Dealing with Issues for Interprocess Communication

Process Synchronization

Last Class: Synchronization Problems!

Process Synchronization. Mehdi Kargahi School of ECE University of Tehran Spring 2008

Background. Module 6: Process Synchronization. Bounded-Buffer (Cont.) Bounded-Buffer. Background

Chapter 7: Process Synchronization. Background

Comp2310 & Comp6310 Concurrent and Distributed Systems

Ada 2005 An introduction for TTK4145

Process Co-ordination OPERATING SYSTEMS

Process Synchronization

Module 6: Process Synchronization

CS3502 OPERATING SYSTEMS

Lesson 6: Process Synchronization

Chapter 7: Process Synchronization. Background. Illustration

Last Class: Monitors. Real-world Examples

Process Synchronization(2)

Chapter 6: Process Synchronization. Operating System Concepts 8 th Edition,

Ada and Real-Time. Prof. Lars Asplund. Mälardalen University, Computer Science

Module 6: Process Synchronization

Process Coordination

Chapter 6: Process Synchronization. Operating System Concepts 8 th Edition,

Deadlock and Starvation

Chapter 6: Synchronization. Chapter 6: Synchronization. 6.1 Background. Part Three - Process Coordination. Consumer. Producer. 6.

Synchronized Methods of Old Versions of Java

Chapter 6: Process Synchronization

Chapter 5: Process Synchronization

Chapter 5: Process Synchronization. Operating System Concepts 9 th Edition

Process Synchronization

Annales UMCS Informatica AI 2 (2004) UMCS. OpenMP parser for Ada

Chapter 6: Process Synchronization. Module 6: Process Synchronization

Today s topic: Real Time Programming with Ada

An Evaluation of the Dynamic and Static Multiprocessor Priority Ceiling Protocol and the Multiprocessor Stack Resource Policy in an SMP System

Chapter 6 Concurrency: Deadlock and Starvation

Operating Systems Antonio Vivace revision 4 Licensed under GPLv3

Object Oriented Programming and Design in Java. Session 18 Instructor: Bert Huang

Real-Time Programming Languages (ADA and Esterel as Examples)

Process Synchronization(2)

PROCESS SYNCHRONIZATION

Process Synchronization

Sections 01 (11:30), 02 (16:00), 03 (8:30) Ashraf Aboulnaga & Borzoo Bonakdarpour

1 Process Coordination

Synchronization. CS 475, Spring 2018 Concurrent & Distributed Systems

Chapter 6: Process Synchronization

! Why is synchronization needed? ! Synchronization Language/Definitions: ! How are locks implemented? Maria Hybinette, UGA

i219 Software Design Methodology 12. Case study 1 Dining philosopher problem Kazuhiro Ogata (JAIST) Outline of lecture

Introduction to Computers and Programming. Structured data types

A Model for Concurrent Object-Oriented Programming

On 17 June 2006, the editor provided the following list via an to the convener:

Deadlocks. Deadlock in Resource Sharing Environment. CIT 595 Spring Recap Example. Representing Deadlock

CSC501 Operating Systems Principles. Process Synchronization

Introduction to Lab 2

Chapter 6: Process Synchronization

Deadlock. Concurrency: Deadlock and Starvation. Reusable Resources

Synchronization Principles II

The Dining Philosophers Problem CMSC 330: Organization of Programming Languages

Lecture 9: Thread Synchronizations. Spring 2016 Jason Tang

Computing Science 114 Solutions to Midterm Examination Tuesday October 19, In Questions 1 20, Circle EXACTLY ONE choice as the best answer

Module 6: Process Synchronization. Operating System Concepts with Java 8 th Edition

Process Synchronization

CS370 Operating Systems

Comp 310 Computer Systems and Organization

Contract-based Programming: a Route to Finding Bugs Earlier

G Programming Languages - Fall 2012

CSc33200: Operating Systems, CS-CCNY, Fall 2003 Jinzhong Niu December 10, Review

The deadlock problem

Concurrency: Deadlock and Starvation. Chapter 6

Transcription:

Specification Low-level programming Resource management Deadlock and starvation Implementation Low-level programming in Ada 95 enables writing device drivers for I/O circuits directly in a high-level language For systems programmed in a high-level language without support for low-level programming, device drivers must be written in the processor s assembly language Calling a device driver facilitates reading or writing data to/ from external units, eg, hard disks, displays and keyboards A device driver conceals the details in the cooperation between software and hardware 1

2

1 Declare a protected object and write the interrupt service routine as a procedure in the protected object 2 Inform the compiler that the procedure is an interrupt service routine, by adding the statement pragma Interrupt_Handler(procedure_name); in the specification of the protected object 3 Declare a variable and assign to it the logical number of the hardware interrupt signal For example: Int_ID : constant := AdaInterruptsNamesint_name; 3

4 Associate the interrupt service routing with the logical number of the hardware interrupt signal, by calling the procedure Attach_Handler(procedure_name access, Int_ID); 5 Inform the compiler about the ceiling priority of the protected object, by adding the statement pragma Interrupt_Priority(priority); in the specification of the protected object The ceiling priority must be identical to the priority of the corresponding hardware interrupt signal When an interrupt is requested, the processor hardware causes the interrupt service routine to be executed at a priority level associated with the interrupt signal Functions, entries, and procedures in the protected object must execute at the same priority level as the interrupt service routine in order to preserve the mutual exclusion properties of the protected object A task that calls a function, entry or procedure in the protected object temporarily assumes the ceiling priority while executing code in the protected object 4

Package System contains the following declarations: subtype Any_Priority is Integer range 1105; subtype Priority is Any_Priority range Any_Priority First 100; subtype Interrupt_Priority is Any_Priority range Priority Last Any_Priority Last; The priority of a protected object can be defined with pragma Interrupt_Priority[(expression)]; Priority levels that are so high that they will mask (block) one or more hardware interrupt signals are of type Interrupt_Priority In Gnu Ada 95 M68K, the priority levels 101105 correspond to the processor s (Motorola 68340) hardware priorities 15 5

6

7

R1, R2 : One_Resource; task A; task body A is R1Acquire; -- task switch from A to B after this line causes deadlock R2Acquire; -- statements using the resources R2Release; R1Release; end A; task B; task body B is R2Acquire; R1Acquire; -- statements using the resources R1Release; R2Release; end B; 8

9

1 Task should, if possible, only use one resource at a time 2 If (1) is not possible, all tasks should request resources in the same order 3 If (1) and (2) are not possible, special precautions should be taken to avoid deadlock For example, resources could be requested using non-blocking calls 10

with Text_IO; use Text_IO; procedure Philosopher_Demo is package Int_IO is new Integer_IO(Integer); use Int_IO; Max : constant Integer := 5; -- five philosophers subtype Phil_No is Integer range 1Max; protected type Room_t is -- room type entry Enter; procedure Leave; private Places : Integer := Max - 1; -- no more than four philosophers end Room_t; -- at the table simultaneously Room : Room_t; -- the room 11

protected type Stick_t is procedure Set_ID(ID : in Phil_no); entry Take; entry Drop; private MyID : Phil_no; Taken : Boolean := false; end Stick_t; -- stick type Stick : array(phil_no) of Stick_t; -- the five sticks task type Philosopher_t is -- philosopher type entry Start(ID : in Phil_no); end Philosopher_t; Philosopher : array(phil_no) of Philosopher_t; -- the five philosophers protected body Stick_t is procedure Set_ID(ID : in Phil_no) is MyID := ID; end Set_ID; entry Take when not Taken is Taken := true; Put( Stick ); Put(MyID, Width => 1); Put_Line( taken ); end Take; entry Drop when Taken is Taken := false; Put( Stick ); Put(MyID, Width => 1); Put_Line( dropped ); end Drop; end Stick_t; 12

protected body Room_t is entry Enter when Places > 0 is Places := Places - 1; Put_Line( One philosopher came ); end Enter; procedure Leave is Places := Places + 1; Put_Line( One philosopher left ); end Leave; end Room_t; task body Philosopher_t is MyID : Phil_No; procedure Think is Put( Philosopher ); Put(MyID, Width => 1); Put_Line( thinks ); delay 30; end Think; procedure Eat is Put( Philosopher ); Put(MyID, Width => 1); Put_Line( eats ); delay 20; end Eat; accept Start(ID : in Phil_No) do MyID := ID; end Start; loop Think; RoomEnter Sticks(MyID)Take; Sticks((MyID mod Max)+1)Take; Eat; Sticks(MyID)Drop; Sticks((MyID mod Max)+1)Drop; RoomLeave; end loop; end Philosopher_t; 13

for i in Phil_No loop Stick(i)Set_ID(i); end loop; for i in Phil_No loop Philosopher(i)Start(i); end loop; end Philosopher_Demo; 14