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.

Slides:



Advertisements
Similar presentations
Operating Systems Semaphores II
Advertisements

Introduction to arrays
Synchronization and Deadlocks
Ch 7 B.
Ch. 7 Process Synchronization (1/2) I Background F Producer - Consumer process :  Compiler, Assembler, Loader, · · · · · · F Bounded buffer.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 5: Process Synchronization.
Intertask Communication and Synchronization In this context, the terms “task” and “process” are used interchangeably.
Chapter 3 The Critical Section Problem
1 Chapter 8 Channels. 2 Concurrent Programming Constructs So far we have seen contructs based on shared memory concept (shared directly – buffer - or.
Informationsteknologi Wednesday, September 26, 2007 Computer Systems/Operating Systems - Class 91 Today’s class Mutual exclusion and synchronization 
1 Concurrency: Mutual Exclusion and Synchronization Chapter 5.
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.
1 Semaphores Special variable called a semaphore is used for signaling If a process is waiting for a signal, it is suspended until that signal is sent.
Program Design and Development
Tuple Spaces and JavaSpaces CS 614 Bill McCloskey.
Chapter 11: Distributed Processing Parallel programming Principles of parallel programming languages Concurrent execution –Programming constructs –Guarded.
Linda: A Data-space Approach to Parallel Programming CSE60771 – Distributed Systems David Moore.
1 Chapter 6: Concurrency: Mutual Exclusion and Synchronization Operating System Spring 2007 Chapter 6 of textbook.
Asynchronous Message Passing EE 524/CS 561 Wanliang Ma 03/08/2000.
A. Frank - P. Weisberg Operating Systems Introduction to Cooperating Processes.
Spaces Dr. Samir Tartir Extracted from Principles of Concurrent and Distributed Programming, Second Edition By M. Ben-Ari.
CS5204 – Operating Systems 1 Communicating Sequential Processes (CSP)
12/1/98 COP 4020 Programming Languages Parallel Programming in Ada and Java Gregory A. Riccardi Department of Computer Science Florida State University.
Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Chapter 8-3 : Distributed Systems Distributed systems Distributed systems Document-based middleware Document-based middleware Coordination-based middleware.
C++ Programming: From Problem Analysis to Program Design, Fifth Edition, Fifth Edition Chapter 7: User-Defined Functions II.
13.1 Matrices and Their Sums
Chapter 3 Parallel Programming Models. Abstraction Machine Level – Looks at hardware, OS, buffers Architectural models – Looks at interconnection network,
1 Concurrency Architecture Types Tasks Synchronization –Semaphores –Monitors –Message Passing Concurrency in Ada Java Threads.
CPS120: Introduction to Computer Science Decision Making in Programs.
1 Lecture 5 (part2) : “Interprocess communication” n reasons for process cooperation n types of message passing n direct and indirect message passing n.
1 Chapter 10 Distributed Algorithms. 2 Chapter Content This and the next two chapters present algorithms designed for loosely-connected distributed systems.
Chapter 6 Programming Languages (1) Introduction to CS 1 st Semester, 2015 Sanghyun Park.
Coordination Models and Languages Part I: Coordination Languages and Linda Part II: Technologies based on Tuple space concept beyond Linda Part III: Comparison.
Fall 2004EE 3563 Digital Systems Design EE 3563 VHDL – Basic Language Elements  Identifiers: –basic identifier: composed of a sequence of one or more.
1 Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Parallel execution Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Loops (cont.). Loop Statements  while statement  do statement  for statement while ( condition ) statement; do { statement list; } while ( condition.
ICS 313: Programming Language Theory Chapter 13: Concurrency.
Synchronization Methods in Message Passing Model.
Chapter 6 Semaphores.
Distributed Programming Concepts and Notations. Inter-process Communication Synchronous Messages Asynchronous Messages Select statement Remote procedure.
CSI 3125, Subprograms, page 1 Subprograms General concepts Parameter passing Functions Subprograms as parameters.
 In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached.  PHP Loops :  In.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 24 Critical Regions.
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.
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 1 Java Programming Review. Introduction Java is platform-independent, meaning that you can write a program once and run it anywhere. Java programs.
CS4315A. Berrached:CMS:UHD1 Process Synchronization Chapter 8.
ARRAYS Multidimensional realities Image courtesy of
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.
Today… Preparation for doing Assignment 1. Invoking methods overview. Conditionals and Loops. Winter 2016CMPE212 - Prof. McLeod1.
LESSON 8: INTRODUCTION TO ARRAYS. Lesson 8: Introduction To Arrays Objectives: Write programs that handle collections of similar items. Declare array.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
Chapter 7: User-Defined Functions II
PROCESS MANAGEMENT IN MACH
Model and complexity Many measures Space complexity Time complexity
Background on the need for Synchronization
“Language Mechanism for Synchronization”
Transactional Memory Semaphores, monitors, and conditional critical regions all suffer from limitations based on lock semantics Naïve synchronization may.
Channels.
Subject : T0152 – Programming Language Concept
Principles of Concurrent and Distributed Programming, Second Edition
Channels.
Channels.
CMPE 152: Compiler Design February 21 Class Meeting
Presentation transcript:

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. Linda is an experimental programming concept unlike ADA or Occam which are fully developed production-quality languages. Linda has been experimentally embedded in several languages Linda has been experimentally embedded in several languages

3 Linda – Ada and Occam Ada and Occam are based on the idea of synchronous communication channels between processes. Ada and Occam are based on the idea of synchronous communication channels between processes. There is coupling in both time and space There is coupling in both time and space Time: The synchronous rendezvous means that both processes must exist simultaneously in order to communicate (must synchronize to pass data). Time: The synchronous rendezvous means that both processes must exist simultaneously in order to communicate (must synchronize to pass data). Space: Addressing by process identification (task name in ADA, channel name in Occam) means that there must be some global scope where processes are defined (processes must know the identity to pass data). Space: Addressing by process identification (task name in ADA, channel name in Occam) means that there must be some global scope where processes are defined (processes must know the identity to pass data).

4 Linda Tuple Space Linda provides uncoupling in both time and space (unsynchronized and no identity check). Linda provides uncoupling in both time and space (unsynchronized and no identity check). This is done by defining a tuple space (TS) which is some form of shared memory containing tuples This is done by defining a tuple space (TS) which is some form of shared memory containing tuples The shared data (tuples) is persistent, meaning that the data can exist after the termination of the process that created them and used by processes that are activated later

5 Tuple Tuples are typed sequences of data like parameter lists in procedure calls. Tuples are typed sequences of data like parameter lists in procedure calls. The concurrent programming primitives of Linda work by pattern matching on the tuple signatures The concurrent programming primitives of Linda work by pattern matching on the tuple signatures Eg: (1,’A’) - (integer, character) Eg: (1,’A’) - (integer, character) (1,2) - (integer, integer) (1,2) - (integer, integer) (‘A’,1) - (character, integer) (‘A’,1) - (character, integer) These tuples can not be matched since their signatures are different.

6 The Linda Primitives (Based on the Terminology used in jBACI) Tuple space is called a board and a tuple is called a note Tuple space is called a board and a tuple is called a note Postnote(v1, v2,...) This statement creates a note from the values of the parameters and posts it on the board. If there are processes blocked waiting for a note matching this parameter signature, an arbitrary one of them is unblocked Postnote(v1, v2,...) This statement creates a note from the values of the parameters and posts it on the board. If there are processes blocked waiting for a note matching this parameter signature, an arbitrary one of them is unblocked Removenote(x1, x2,...) The parameters must be variables. The statement removes a note that matches the parameter signature from the board and assigns its values to the parameters. If no matching note exists, the process is blocked. If there is more than one matching note, an arbitrary one is removed Removenote(x1, x2,...) The parameters must be variables. The statement removes a note that matches the parameter signature from the board and assigns its values to the parameters. If no matching note exists, the process is blocked. If there is more than one matching note, an arbitrary one is removed Readnote(x1, x2,...) Like removenote, but it leaves the note on the board Readnote(x1, x2,...) Like removenote, but it leaves the note on the board

7 An Example Suppose that the following statements are executed Suppose that the following statements are executed postnote(‘a’, 10, 20) postnote(‘a’, 30) postnote(‘a’, false, 40) postnote(‘a’, true, 50)  Execute the statements below Integer m, integer n, boolean b 1. removenote(‘b’, m, n)process is blocked 2. removenote(‘a’, m, n)process matches and removes note (‘a’, 10, 20) 3. readnote(‘a’, m)process matches and reads note (‘a’, 30) – no removal 4. removenote(‘a’, n)note (‘a’, 30) is removed 5. removenote(‘a’, m, n)process is blocked 6. removenote(‘a’, b, n)one of the (‘a’, true, 50) or (‘a’, false, 40) is removed 7. removenote(‘a’, b, m)the other note is removed 8. postnote(‘b’, 60, 70)process blocked in (1) is unblocked and the note is removed  The contents of the board

8 Implementing a General Semaphore in Linda Post k notes as the initial value of a semaphore Post k notes as the initial value of a semaphore do K times postnote(‘s’) Removenote is equivalent to wait and postnote to signal Removenote is equivalent to wait and postnote to signal

9 Formal Parameters Client posts a note ‘S’ with process ID, service request and parameters for the service and waits for a result note ‘R’ with matching ID and the result Client posts a note ‘S’ with process ID, service request and parameters for the service and waits for a result note ‘R’ with matching ID and the result The server removes a service note ‘S’ from some client with service request s and parameter p. When the service is over it posts a result note ‘R’ to the same client The server removes a service note ‘S’ from some client with service request s and parameter p. When the service is over it posts a result note ‘R’ to the same client Here, a server provides several different service requests at the same time Here, a server provides several different service requests at the same time

10 Match for a Specific Value The server in the above algorithm waits for a specific service using a formal parameter ‘s=‘ The server in the above algorithm waits for a specific service using a formal parameter ‘s=‘

11 Another Example The formal parameter ‘count=‘ in the consumer makes sure that the values are consumed in the order they are produced The formal parameter ‘count=‘ in the consumer makes sure that the values are consumed in the order they are produced

12 Linda in j BACI A note in jBACI consists of a triple: a character and two integer values.. A note in jBACI consists of a triple: a character and two integer values.. The first parameter must be a character value, while the two optional parameters must be integer variables. The first parameter must be a character value, while the two optional parameters must be integer variables. The operations can be called with one, two or three parameters; unused integer parameters are given the default value : The operations can be called with one, two or three parameters; unused integer parameters are given the default value : postnote('a'); { Equivalent to postnote('a', , ) } postnote('a', 5); { Equivalent to postnote('a', 5, ) } postnote('a', 5, 10);

13 Linda in j BACI (Cont.) For historical reasons, there are two syntaxes for matching the values of a tuple to the current values of the parameters: For historical reasons, there are two syntaxes for matching the values of a tuple to the current values of the parameters: If the equal sign “=“ appears after a variable, the value of the note in that position must match the current value of that variable. For example, the following statements will remove any tuple of the form ('a',...,5): If the equal sign “=“ appears after a variable, the value of the note in that position must match the current value of that variable. For example, the following statements will remove any tuple of the form ('a',...,5): i2 := 5; removenote('a',i1,i2=); removenoteeq (readnoteeq) is like removenote (readnote), but the two parameters values of the note must match the current values of both variables. For example, the following statements will remove only the tuple ('a',1,2): removenoteeq (readnoteeq) is like removenote (readnote), but the two parameters values of the note must match the current values of both variables. For example, the following statements will remove only the tuple ('a',1,2): i1 := 1; i2 := 2; removenoteeq('a',i1,i2); Note that removenoteeq('a',i1,i2) is equivalent to removenote('a',i1=,i2=). Note that removenoteeq('a',i1,i2) is equivalent to removenote('a',i1=,i2=).

14 Matrix Multiplication Algorithm in Linda Notes identified as Notes identified as ‘E’ contain the elements passed from north to south ‘E’ contain the elements passed from north to south ‘S’ contain the partial sums passed from east to west ‘S’ contain the partial sums passed from east to west

Matrix Multiplication in jBaci Multiply two matrices A and B to get matrix C Multiply two matrices A and B to get matrix C A x B= C A x B= C x 0 1 0=

16 Matrix Multiplication in jBaci program LindaMultiplication; {multiply two 3x3 matrices A and B - 9 Workers} var a,b :array[1..3,1..3] of integer; process initandprint; end; process worker; end; begincobegininitandprint; worker; worker; worker; coend;end.

17 Matrix Multiplication in jBaci (Cont.) process initandprint; varc, i, j, k: integer; begin {array A} {array A} a[1,1]:=1; a[1,2]:=2; a[1,3]:=3; a[1,1]:=1; a[1,2]:=2; a[1,3]:=3; a[2,1]:=4; a[2,2]:=5; a[2,3]:=6; a[2,1]:=4; a[2,2]:=5; a[2,3]:=6; a[3,1]:=7; a[3,2]:=8; a[3,3]:=9; a[3,1]:=7; a[3,2]:=8; a[3,3]:=9; {array B} {array B} b[1,1]:=1; b[1,2]:=0; b[1,3]:=2; b[1,1]:=1; b[1,2]:=0; b[1,3]:=2; b[2,1]:=1; b[2,2]:=2; b[2,3]:=1; b[2,1]:=1; b[2,2]:=2; b[2,3]:=1; b[3,1]:=1; b[3,2]:=1; b[3,3]:=1; b[3,1]:=1; b[3,2]:=1; b[3,3]:=1; {post worker notes – column and row numbers} {post worker notes – column and row numbers} postnote('w',1,1); postnote('w',1,2); postnote('w',1,3); postnote('w',1,1); postnote('w',1,2); postnote('w',1,3); postnote('w',2,1); postnote('w',2,2); postnote('w',2,3); postnote('w',2,1); postnote('w',2,2); postnote('w',2,3); postnote('w',3,1); postnote('w',3,2); postnote('w',3,3); postnote('w',3,1); postnote('w',3,2); postnote('w',3,3); postnote('N',1); {Next job counter} postnote('N',1); {Next job counter} { write the resulting matrix when computations are over} { write the resulting matrix when computations are over} for i:= 1 to 3 do for j:=1 to 3 do begin k:=i*10+j; removenote('c',k,c); writeln('c',k,'=',c); end; for i:= 1 to 3 do for j:=1 to 3 do begin k:=i*10+j; removenote('c',k,c); writeln('c',k,'=',c); end;end;

18 Matrix Multiplication in jBaci (Cont.) process worker; var element, row, col, r, v :integer; begin while true do while true do begin begin removenote('N',element); removenote('N',element); postnote('N',element+1); postnote('N',element+1); if element > 3*3 then suspend; if element > 3*3 then suspend; removenote('w',row,col); removenote('w',row,col); v:=0; v:=0; for r:=1 to 3 do v:=v+a[row,r]*b[r,col]; for r:=1 to 3 do v:=v+a[row,r]*b[r,col]; r:= row*10+col; postnote('c',r,v); r:= row*10+col; postnote('c',r,v); end; end;end;

19 Producer-Consumer with Linda One producer and 3 consumers. One producer and 3 consumers. Producer puts a message on the Linda board Producer puts a message on the Linda board All consumers read the same message and the last one to read removes the note forever All consumers read the same message and the last one to read removes the note forever program producerandconsumers; constn=3;{3 consumers} process producer; end; process consumer; end; begin cobegin producer; consumer; consumer; consumer; coend; cobegin producer; consumer; consumer; consumer; coend;end.

20 Producer-Consumer with Linda (Cont.) process producer; var i: integer := 34; c: char; c: char;begin while (i < 126) do {characters 34 to 126 are printable characters} while (i < 126) do {characters 34 to 126 are printable characters} begin begin c:= i; {convert value to character - first parameter of postnote is a character!} i:= i+1; {increment for the next message} postnote(c,n) {post a message} end; end;end; process consumer; Varc :char; i :integer :=34; i :integer :=34; j :integer; j :integer;begin while (i < 126) do while (i < 126) do begin begin c:= i; removenote(c,j); {remove the note} j:= j-1; if j <> 0 then postnote(c,j); {if not the last process then put note with one less count} i:= i+1 {increment for the next message} end; end;end;

21 Linda Simulation of Rendezvous Ada rendezvous to be simulated Ada rendezvous to be simulated accept Proc(I: in integer; C: in character; B: out boolean) do end Proc; Proc(65, ‘X’, B); --- call to entry

22 Linda Simulation of Rendezvous integer pid, i; character c -- code for accepting process readnote(“Proc”, pid, i, c); Proc(I, C, B); -- accept “proc” code procedure postnote(pid, B); -- code for calling process readnote(“Proc”, 24, 65, ‘X’); postnote(24, B: Boolean);