Using a simple Rendez-Vous mechanism in Java

Slides:



Advertisements
Similar presentations
Concurrency Important and difficult (Ada slides copied from Ed Schonberg)
Advertisements

Chapter 6: Process Synchronization
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 5: Process Synchronization.
5.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Chapter 5: CPU Scheduling.
Lab2: Semaphores and Monitors. Credits Material in this slide set is from G. Andrews, “Foundation of Multithreaded, Parallel, and Distributed Programming”,
1 Concurrency: Mutual Exclusion and Synchronization Chapter 5.
1 Concurrency Specification. 2 Outline 4 Issues in concurrent systems 4 Programming language support for concurrency 4 Concurrency analysis - A specification.
1 Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Introduction in algorithms and applications Introduction in algorithms and applications Parallel machines and architectures Parallel machines and architectures.
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.
Threads Clients Servers Code Migration Software Agents Summary
Concurrency CS 510: Programming Languages David Walker.
Chapter 11: Distributed Processing Parallel programming Principles of parallel programming languages Concurrent execution –Programming constructs –Guarded.
Chapter 2: Impact of Machine Architectures What is the Relationship Between Programs, Programming Languages, and Computers.
Multithreading in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
A. Frank - P. Weisberg Operating Systems Introduction to Tasks/Threads.
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.
Concurrency - 1 Tasking Concurrent Programming Declaration, creation, activation, termination Synchronization and communication Time and delays conditional.
On the Duality of Operating System Structures Hugh C. Lauer Xerox Corporation Roger M. Needham Cambridge University Presented By: Ashwini Kulkarni.
Synchronization CSCI 444/544 Operating Systems Fall 2008.
Fundamentals of Python: From First Programs Through Data Structures
Threading in Java – a Tutorial QMUL IEEE SB. Why Threading When we need to run two tasks concurrently So multiple parts (>=2) of a program can run simultaneously.
Discussion Week 3 TA: Kyle Dewey. Overview Concurrency overview Synchronization primitives Semaphores Locks Conditions Project #1.
Java Programming: Advanced Topics
Concurrency, Mutual Exclusion and Synchronization.
Threads in Java. History  Process is a program in execution  Has stack/heap memory  Has a program counter  Multiuser operating systems since the sixties.
12/1/98 COP 4020 Programming Languages Parallel Programming in Ada and Java Gregory A. Riccardi Department of Computer Science Florida State University.
Multithreading in Java Project of COCS 513 By Wei Li December, 2000.
1 Concurrent Languages – Part 1 COMP 640 Programming Languages.
Chapter 13 Concurrency. Copyright © 2012 Addison-Wesley. All rights reserved.1-2 Introduction Concurrency can occur at four levels: –Machine instruction.
1 Web Based Programming Section 8 James King 12 August 2003.
Semaphores, Locks and Monitors By Samah Ibrahim And Dena Missak.
1 Copyright © 1998 by Addison Wesley Longman, Inc. Chapter 12 Concurrency can occur at four levels: 1. Machine instruction level 2. High-level language.
1 Concurrency Architecture Types Tasks Synchronization –Semaphores –Monitors –Message Passing Concurrency in Ada Java Threads.
Internet Software Development Controlling Threads Paul J Krause.
1 Concurrency: Mutual Exclusion and Synchronization Chapter 5.
1 Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Threaded Programming in Python Adapted from Fundamentals of Python: From First Programs Through Data Structures CPE 401 / 601 Computer Network Systems.
ICS 313: Programming Language Theory Chapter 13: Concurrency.
PZ12B Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ12B - Synchronization and semaphores Programming Language.
Synchronization and semaphores Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Java Thread and Memory Model
Concurrency Control 1 Fall 2014 CS7020: Game Design and Development.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
Multi-Threading in Java
13-1 Chapter 13 Concurrency Topics Introduction Introduction to Subprogram-Level Concurrency Semaphores Monitors Message Passing Java Threads C# Threads.
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.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
REVIEW OF “ON THE DUALITY OF OPERATING SYSTEM STRUCTURES” Paper by Hugh C. Lauer and Roger M. Needham Presentation by Erin Chapman.
Java Thread Programming
Object Oriented Programming in
Processes and threads.
“Language Mechanism for Synchronization”
Processes and Threads Processes and their scheduling
Chapter 2 Processes and Threads Today 2.1 Processes 2.2 Threads
Lecture 21 Concurrency Introduction
Transactional Memory Semaphores, monitors, and conditional critical regions all suffer from limitations based on lock semantics Naïve synchronization may.
Multithreading.
Multithreaded Programming
Concurrency: Mutual Exclusion and Process Synchronization
Subject : T0152 – Programming Language Concept
CSE 451: Operating Systems Autumn 2003 Lecture 7 Synchronization
CSE 451: Operating Systems Autumn 2005 Lecture 7 Synchronization
CSE 451: Operating Systems Winter 2003 Lecture 7 Synchronization
Representation and Management of Data on the Internet
CS703 – Advanced Operating Systems
Software Engineering and Architecture
Synchronization and semaphores
Presentation transcript:

Using a simple Rendez-Vous mechanism in Java João Duarte duarte@kiv.zcu.cz

Motivation Real time programs Cooperating threads sharing the same context (data structures, IO devices, etc.) Need for interaction

Interaction Interaction primitives: Structured interaction mechanisms: Locks Semaphores Structured interaction mechanisms: Rendez-Vous (ADA) Monitors (Java)

Java Monitors Monitor: passive object providing synchronized methods Dynamic model of Java multithreading computation: Dynamic set of monitors Dynamic set of threads Threads interact indirectly through monitor services calls. Direct interaction of threads was suppressed for safety reasons (e.g. functions resume() and suspend() not supported after JDK 1.3) atomically executed services that can be called from threads.

ADA’s Rendez-Vous Common execution of a code section by two threads (tasks) Asymmetric, “roles” of both tasks are different: The client calls rendezvous (and needs “to know” the partner) The server accepts rendezvous (and does not need to know the client) Synchronous, the first task reaching the rendezvous point waits for its partner

ADA’s Rendez-Vous Data of both “actors” of rendezvous can be used within the execution Every transformation of tasks data can be programmed (and atomically executed) as a rendezvous Dynamic model of Ada multithreading computation: Set of tasks that interact directly using the rendezvous mechanism

ADA’s Rendez-Vous - Server Example Initialization of Entries Beginning of task Store first Item

ADA’s Rendez-Vous - Server Example Select statement with two alternatives

ADA’s Rendez-Vous – Client Example Create the Task Acess as a normal variable

Using ADA’s Rendez-Vous in Java – Why? Allows “pure monitor” (i.e. server) thread. More general model of parallel (concurrent) computation. An easy way how to synchronize two threads in a specified point of their execution and join data exchange/transformation. Asymetric allows pure monitor.. Direct interaction of threads -> more general model

Using ADA’s Rendez-Vous in Java – Why? A way how to construct threads with “two faces”, i.e. part of their life they can act as clients and another part as servers A way how to construct multiple-mode monitors, e.g. monitors that provides various sets of services within various stages of their life.

Implementing Rendez-Vous in Java - Keypoints As simple as possible,no need to include all the facilities of the Ada rendezvous implementation No need for any special JVM or pre-processor Construct an object type whose instance can manage an entry synchronization (i.e. to every single entry should be assigned one synchronization object). Simple -> all the possibilities of the select statement

Implementing Rendez-Vous in Java - Keypoints Methods of a dedicated synchronization object should be called only from the server side of rendezvous. To call an entry from the client side should be as simple as the Java conventional public method call It is necessary to implement a simple form of the Ada select statement Rendezvous implementation is invisible for the client

Implementing Rendez-Vous in Java – State Machine

Implementing Rendez-Vous in Java – Entry class

Implementing Rendez-Vous in Java – Entry class

Implementing Rendez-Vous in Java – Entry class

Using the Entry class Uses Entry e1 Both use Entry e2 Code executed inside the Rendez Vous Methods called by the client Both use Entry e2

Using the Entry class here it accepts only entry_1() call it accepts either entry_21() or entry_22() call A simple form of Ada-like select statement can be easily implemented when a group of entries uses the same synchronization object. it can call entry of another server as well

Conclusion Simple and easy to use Just one class needed Extends possibilities on how to design Java multithreaded program architecture

Future work Add EntrySet class Include all the possibilities of the select statement: Boolean guards Delays else alternative

Web Source code and examples: http://www.kiv.zcu.cz/~stracek/ppr/java/randez/ Email: duarte@kiv.zcu.cz