12/1/98 COP 4020 Programming Languages Parallel Programming in Ada and Java Gregory A. Riccardi Department of Computer Science Florida State University.

Slides:



Advertisements
Similar presentations
Computer Science 320 Clumping in Parallel Java. Sequential vs Parallel Program Initial setup Execute the computation Clean up Initial setup Create a parallel.
Advertisements

Ch 7 B.
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.
Multithreaded Programs in Java. Tasks and Threads A task is an abstraction of a series of steps – Might be done in a separate thread – Java libraries.
CS 5704 Fall 00 1 Monitors in Java Model and Examples.
Chapter 7 Threads  Threads & Processes  Multi Threading  Class Thread  Synchronized Methods  Wait & Notify.
PZ11B Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ11B - Parallel execution Programming Language Design.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L19 (Chapter 24) Multithreading.
Concurrency in Ada What concurrency is all about Relation to operating systems Language facilities vs library packages POSIX threads Ada concurrency Real.
Inter Process Communication:  It is an essential aspect of process management. By allowing processes to communicate with each other: 1.We can synchronize.
Synchronization in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Java ThreadsGraphics Programming Graphics Programming: Java Threads.
Definitions Process – An executing program
29-Jun-15 Java Concurrency. Definitions Parallel processes—two or more Threads are running simultaneously, on different cores (processors), in the same.
Multithreading in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
1 Organization of Programming Languages-Cheng (Fall 2004) Concurrency u A PROCESS or THREAD:is a potentially-active execution context. Classic von Neumann.
Concurrency - 1 Tasking Concurrent Programming Declaration, creation, activation, termination Synchronization and communication Time and delays conditional.
1 Threads Chapter 4 Reading: 4.1,4.4, Process Characteristics l Unit of resource ownership - process is allocated: n a virtual address space to.
Parallel Processing (CS526) Spring 2012(Week 8).  Thread Status.  Synchronization in Shared Memory Programming(Java threads ) ◦ Locks ◦ Barriars.
Comparative Programming Languages hussein suleman uct csc304s 2003.
Java Programming: Advanced Topics
Object Oriented Analysis & Design SDL Threads. Contents 2  Processes  Thread Concepts  Creating threads  Critical sections  Synchronizing threads.
Threads in Java. History  Process is a program in execution  Has stack/heap memory  Has a program counter  Multiuser operating systems since the sixties.
Threading and Concurrency Issues ● Creating Threads ● In Java ● Subclassing Thread ● Implementing Runnable ● Synchronization ● Immutable ● Synchronized.
Lecture 5 : JAVA Thread Programming Courtesy : MIT Prof. Amarasinghe and Dr. Rabbah’s course note.
Definitions & Scenarios. Acknowledgements  This tutorial is based in part on Concurrency: State Models & Java Programming by Jeff Magee and Jeff Kramer.
Multi-Threaded Application CSNB534 Asma Shakil. Overview Software applications employ a strategy called multi- threaded programming to split tasks into.
111 © 2002, Cisco Systems, Inc. All rights reserved.
Java Software Solutions Lewis and Loftus Chapter 14 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Advanced Flow of Control --
CS 152: Programming Language Paradigms May 7 Class Meeting Department of Computer Science San Jose State University Spring 2014 Instructor: Ron Mak
CPS 506 Comparative Programming Languages
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 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.
Li Tak Sing COMPS311F. Case study: consumers and producers A fixed size buffer which can hold at most certain integers. A number of producers which generate.
Threading Eriq Muhammad Adams J
Parallel execution Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Using a simple Rendez-Vous mechanism in Java
ICS 313: Programming Language Theory Chapter 13: Concurrency.
OPERATING SYSTEMS Frans Sanen.  Recap of threads in Java  Learn to think about synchronization problems in Java  Solve synchronization problems in.
Java Thread and Memory Model
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.
Dr. R R DOCSIT, Dr BAMU. Basic Java :Multi Threading Cont. 2 Objectives of This Session Explain Synchronization in threads Demonstrate use of.
15.1 Threads and Multi- threading Understanding threads and multi-threading In general, modern computers perform one task at a time It is often.
Concurrency Control 1 Fall 2014 CS7020: Game Design and Development.
Multi-Threading in Java
Multithreaded programming  Java provides built-in support for multithreaded programming. A multithreaded program contains two or more parts that can run.
13-1 Chapter 13 Concurrency Topics Introduction Introduction to Subprogram-Level Concurrency Semaphores Monitors Message Passing Java Threads C# Threads.
1 Parallel execution Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Assembly Language Co-Routines
1 5-High-Performance Embedded Systems using Concurrent Process (cont.)
CSC CSC 143 Threads. CSC Introducing Threads  A thread is a flow of control within a program  A piece of code that runs on its own. The.
1 Threads in Java Jingdi Wang. 2 Introduction A thread is a single sequence of execution within a program Multithreading involves multiple threads of.
Concurrency in Java MD. ANISUR RAHMAN. slide 2 Concurrency  Multiprogramming  Single processor runs several programs at the same time  Each program.
Concurrent Programming in Java Based on Notes by J. Johns (based on Java in a Nutshell, Learning Java) Also Java Tutorial, Concurrent Programming in Java.
1 Sections 6.4 – 6.5 Methods and Variables Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
Multithreading.
5-High-Performance Embedded Systems using Concurrent Process (cont.)
Definitions Concurrent program – Program that executes multiple instructions at the same time. Process – An executing program (the running JVM for Java.
Lecture 12 Concepts of Programming Languages
MODERN OPERATING SYSTEMS Third Edition ANDREW S
Multithreading.
Multithreading.
Multithreaded Programming
Shared Memory Programming
Subject : T0152 – Programming Language Concept
NETWORK PROGRAMMING CNET 441
Threads and Multithreading
Parallel execution Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Presentation transcript:

12/1/98 COP 4020 Programming Languages Parallel Programming in Ada and Java Gregory A. Riccardi Department of Computer Science Florida State University December 1, 1998

12/1/98 Two Strategies for Parallelism n Ada, task synchronization n Tasks execute independently n Rendezvous provides synchronized execution between 2 tasks n Java, method and object synchronization n Threads execute independently n Synchronized methods are executed as critical sections n only one execution per synch. method n Synchronized statements depend on objects n one execution per object of any statement

12/1/98 Tasks in Ada n Ada supports a program unit declaration of tasks n Each task object represents a separate unit of execution n Tasks can share objects through usual global packages and nesting n Task T is... end; -- declaration of a single task object n Task type TT is... end; -- type for many objects n T1: TT; T2: TT; -- T1 and T2 are task objects n Example using global variables g and h n task type TT ; n task body TT is x: integer; begin x := g; h := x; end; n -- each task of type TT uses global g n T1, T2: TT; g:= 4; g := 5; g:=6; n what is value of h? n this is a race condition. n type ptrT is access T;

12/1/98 Synchronization and Communication n Synchronization is required to eliminate race conditions. n Ada tasks synchronize by 'rendezvous' n Two tasks, one is caller, one is receiver n Caller requests a meeting for a specific purpose n Receiver offers to accept a meeting for any of a specific collection of purposes n Meeting takes place: n Caller passes information to receiver and waits n Receiver gets information, executes by itself, passes information back and continues its execution n Caller gets information from receiver and continues n Place (or purpose) is called entry like procedure specification n Call is an entry call, syntax exactly like procedure call n Receive is an accept, very much like a procedure body

Task Execution and Termination n declare -- beginning of block n T1: TT; -- T1 gets ready to execute, stack created n begin -- T1 begins its execution here n -- T1 executes in parallel with this code n end; -- block is not completely finished until T1 finishes. n declare -- beginning of block n Tptr: TT * = new TT; -- *Tptr gets ready to execute, and begins n begin n -- T1 executes in parallel with this code n end; -- block does not wait for *Tptr to finish. n Terminate T1; -- immediately terminates execution of T1

12/1/98 Storage Management for Tasks n Does each task need its own stack? n Each task has access to other stacks appropriate to its nesting n Guarantees of mutual exclusion n Two tasks that wish to access shared objects n Access only during rendezvous, receiver accesses object and passes value to caller n Use rendezvous to synchronize n Caller references variable, then makes entry call n Receiver waits to reference until it has received a call n The accept statement is guaranteed to execute while the caller is blocked. n Create a third task to provide access to shared data n New task is a monitor. n Create a message passing task to send/receive messages

12/1/98 Threads in Java n class MyThread extends Thread { public void run() {// code for execution n MyThread threadVar = new MyThread(); threadVar.start(); n class MyRunner implements Runnable { public void run() { // code for execution n MyRunner runVar = new MyRunner(); new Thread(runVar).start(); n Other methods n stop, sleep, suspend, resume, yield, destroy

12/1/98 Synchronization in Java n Synchronization uses locks and monitors n Objects can be locked n Methods can have exclusive execution n synchronized statement n synchronized (expression) statement n obtain lock for object or array then execute stmt n Example of sorting a shared array n synchronized (a) {//sort array here…} n synchronized modifier n method that is executed exclusively n class MyObject { n public synchronized void update()...

12/1/98 Distributed Objects in Java n Java supports communication between programs n java.net.Socket and Java.net.ServerSocket n To send objects to another program n Socket sock = new Socket(host,port); ObjectOutputStream out = new ObjectOutputStream (sock.getOutputStream(); out.writeObject(out); // object is transferred! n To receive object, n create a server socket n open ObjectInputStream n readObject