VDM++ Tutorial Concurrency. Overview Introduction Concurrency primitives in VDM++ Example: POP3 Server Concurrency and VDMTools ®

Slides:



Advertisements
Similar presentations
Operating Systems Semaphores II
Advertisements

A Simple Critical Section Protocol There are N concurrent processes P 1,…,P N that share some data. A process accessing the shared data is said to execute.
Ch. 7 Process Synchronization (1/2) I Background F Producer - Consumer process :  Compiler, Assembler, Loader, · · · · · · F Bounded buffer.
Introduction To System Analysis and Design
Transaction Processing Lecture ACID 2 phase commit.
TCP/IP Protocol Suite 1 Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 17 Introduction to the Application.
Concurrency CS 510: Programming Languages David Walker.
Chapter 11: Distributed Processing Parallel programming Principles of parallel programming languages Concurrent execution –Programming constructs –Guarded.
Client Server Design Alternatives© Dr. Ayman Abdel-Hamid, CS4254 Spring CS4254 Computer Network Architecture and Programming Dr. Ayman A. Abdel-Hamid.
Race Conditions CS550 Operating Systems. Review So far, we have discussed Processes and Threads and talked about multithreading and MPI processes by example.
A. Frank - P. Weisberg Operating Systems Introduction to Cooperating Processes.
Fundamentals of Python: From First Programs Through Data Structures
Using Data Active Server Pages Objectives In this chapter, you will: Learn about variables and constants Explore application and session variables Learn.
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 4 Web technologies: HTTP, CGI, PHP,Java applets)
VDM++ Tutorial Implementing in Java. Overview Introduction Overview of Java code generation Options for Java code generation Keep tags POP3 Example.
Threads in Java. History  Process is a program in execution  Has stack/heap memory  Has a program counter  Multiuser operating systems since the sixties.
Concurrency: Mutual Exclusion and Synchronization Chapter 5.
TIVDM2Introduction, AST extensions and Concurrency in VDM++ 1 Introduction to VDM2, Simple AST extensions and Concurrency in VDM++ Professor Peter Gorm.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Introduction to Concurrency.
1 Concurrency Architecture Types Tasks Synchronization –Semaphores –Monitors –Message Passing Concurrency in Ada Java Threads.
VDM++ Tutorial Model Quality. Overview Introduction Assessing internal consistency Assessing external consistency.
1 Lecture 5 (part2) : “Interprocess communication” n reasons for process cooperation n types of message passing n direct and indirect message passing n.
4061 Session 21 (4/3). Today Thread Synchronization –Condition Variables –Monitors –Read-Write Locks.
Threaded Programming in Python Adapted from Fundamentals of Python: From First Programs Through Data Structures CPE 401 / 601 Computer Network Systems.
Synchronization Methods in Message Passing Model.
Lecture 8 Page 1 CS 111 Online Other Important Synchronization Primitives Semaphores Mutexes Monitors.
Middleware Services. Functions of Middleware Encapsulation Protection Concurrent processing Communication Scheduling.
Processes CSCI 4534 Chapter 4. Introduction Early computer systems allowed one program to be executed at a time –The program had complete control of the.
Multithreading Chapter Introduction Consider ability of human body to ___________ –Breathing, heartbeat, chew gum, walk … In many situations we.
1 Interprocess Communication (IPC) - Outline Problem: Race condition Solution: Mutual exclusion –Disabling interrupts; –Lock variables; –Strict alternation.
Threads Doing Several Things at Once. Threads n What are Threads? n Two Ways to Obtain a New Thread n The Lifecycle of a Thread n Four Kinds of Thread.
Multi-Threading in Java
13-1 Chapter 13 Concurrency Topics Introduction Introduction to Subprogram-Level Concurrency Semaphores Monitors Message Passing Java Threads C# Threads.
Thread basics. A computer process Every time a program is executed a process is created It is managed via a data structure that keeps all things memory.
Chapter 7 - Interprocess Communication Patterns
1 Distributed Systems Distributed Object-Based Systems Chapter 10.
JavaScript 101 Introduction to Programming. Topics What is programming? The common elements found in most programming languages Introduction to JavaScript.
Operating Systems CMPSC 473 Signals, Introduction to mutual exclusion September 28, Lecture 9 Instructor: Bhuvan Urgaonkar.
Homework Assignment #1 J. H. Wang Sep. 22, Homework #1 Chap.2: 2.10 Chap.3: 3.1, 3.4, 3.5* (or 3.6*) Chap.4: 4.6, 4.8* (Optional: End-of-chapter.
Software Systems Verification and Validation Laboratory Assignment 4 Model checking Assignment date: Lab 4 Delivery date: Lab 4, 5.
Chapter 7 Classes and Methods III: Static Methods and Variables Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition)
1 Processes and Threads Part II Chapter Processes 2.2 Threads 2.3 Interprocess communication 2.4 Classical IPC problems 2.5 Scheduling.
M1G Introduction to Programming 2 2. Creating Classes: Game and Player.
1 5-High-Performance Embedded Systems using Concurrent Process (cont.)
Flow Control in Imperative Languages. Activity 1 What does the word: ‘Imperative’ mean? 5mins …having CONTROL and ORDER!
pThread synchronization
Last Class: Introduction
Threaded Programming in Python
Background on the need for Synchronization
“Language Mechanism for Synchronization”
Computational Models Database Lab Minji Jo.
Lecture 25 More Synchronized Data and Producer/Consumer Relationship
Lecture 21 Concurrency Introduction
5-High-Performance Embedded Systems using Concurrent Process (cont.)
143a discussion session week 3
Definitions Concurrent program – Program that executes multiple instructions at the same time. Process – An executing program (the running JVM for Java.
Java Byte IPC: Part 6-Summary
Inter-Process Communication and Synchronization
Distributed Systems - Comp 655
Multithreading Chapter 23.
Realizing Concurrency using Posix Threads (pthreads)
Threads and Data Sharing
Concurrency: Mutual Exclusion and Process Synchronization
Threaded Programming in Python
Realizing Concurrency using Posix Threads (pthreads)
Object Oriented Programming in java
CS561 Computer Architecture Hye Yeon Kim
CSE 332: Concurrency and Locks
Synchronization and liveness
Presentation transcript:

VDM++ Tutorial Concurrency

Overview Introduction Concurrency primitives in VDM++ Example: POP3 Server Concurrency and VDMTools ®

Introduction Why Concurrency? Why Concurrency in VDM++? What’s possible? What’s not possible?

Overview Introduction Concurrency primitives in VDM++ Example: POP3 Server Concurrency and VDMTools ®

Concurrency Primitives in VDM++ Concurrency in VDM++ is based on threads Threads communicate using shared objects Synchronization on shared objects is specified using permission predicates

Threads Modelled by a class with a thread section class SimpleThread thread let - = new IO().echo(”Hello World!”) end SimpleThread Thread execution begins using start statement with an instance of a class with a thread definition start(new SimpleThread)

Thread Communication Threads operating in isolation have limited use. In VDM++ threads communicate using shared objects.

Producer-Consumer Example Producer has a thread which repeatedly places data in the buffer Consumer has a thread which repeatedly fetches data from the buffer

The Buffer Class class Buffer instance variables data : [seq of char] := nil operations public put : seq of char ==> () put(newData) == data := newData; public get : () ==> seq of char get() == let oldData = data in ( data := nil; return oldData ) end Buffer

Permission Predicates What if the producer thread generates values faster than the consumer thread can consume them? Shared objects require synchronization. Synchronization is achieved in VDM++ using permission predicates. A permission predicate describes when an operation call may be executed. If a permission predicate is not satisfied, the operation call blocks.

Permission Predicates: Details Permission predicates are described in the sync section of a class sync per => predicate The predicate may refer to the class’s instance variables. The predicate may also refer to special variables known as history counters.

History Counters History counters provide information about the number of times an operation has been requested activated completed CounterDescription #req(op)The number of times that op has been requested #act(op)The number of times that op has been activated #fin(op)The number of times that op has been completed #active(op)The number of currently active invocations of op (#req - #fin)

The Buffer Synchronized Assuming the buffer does not lose data, there are two requirements: It should only be possible to get data, when the producer has placed data in the buffer. It should only be possible to put data when the consumer has fetched data from the buffer. The following permission predicates could model these requirements: per Put => data = nil per Get => data <> nil

The Buffer Synchronized (2) The previous predicates could also have been written using history counters: For example per Get => #fin(Put) - #fin(Get) = 1

Mutual Exclusion Another problem could arise with the buffer: what if the producer produces and the consumer consumes at the same time? The result could be non-deterministic and/or counter-intuitive. VDM++ provides the keyword mutex mutex(Put, Get) Shorthand for per Put => #active(Get) = 0 per Get => #active(Put) = 0

Overview Introduction Concurrency primitives in VDM++ Example: POP3 Server Concurrency and VDMTools ®

Example: POP3 Server Protocol which allows clients to fetch messages from a server. Server contains a collection of messages for a number of users. Server is typically capable of communicating with multiple clients concurrently.

Class Structure

Behaviour The server listens constantly for clients. When a client initiates contact, a client handler is spawned. The client handler then responds to commands from the client, until the client terminates the session.

Sequence Diagram

Overview Introduction Concurrency primitives in VDM++ Example: POP3 Server Concurrency and VDMTools ®

VDMTools ® provides Type checking of thread and sync sections of a class. Execution of threads, using a variety of scheduling algorithms, which the user can select. Code generation of thread and sync sections of a class (Java only).

Summary Language primitives for support of concurrency threads permission predicates POP3 example – see forthcoming book for more details! Support within VDMTools ®