A Generalized Deadlock-Free Process Calculus Eijiro Sumii Naoki Kobayashi University of Tokyo.

Slides:



Advertisements
Similar presentations
Types and Programming Languages Lecture 4 Simon Gay Department of Computing Science University of Glasgow 2006/07.
Advertisements

Type Checking, Inference, & Elaboration CS153: Compilers Greg Morrisett.
Semantics Static semantics Dynamic semantics attribute grammars
Inference of progress properties for (multi party) sessions Mario Coppo (Universita’ di Torino) joint work with Mariangiola Dezani, Nobuko Yoshida Lisbon,
Budapest University of Technology and EconomicsDagstuhl 2004 Department of Measurement and Information Systems 1 Towards Automated Formal Verification.
Formal Semantics of Programming Languages 虞慧群 Topic 6: Advanced Issues.
1 Mooly Sagiv and Greta Yorsh School of Computer Science Tel-Aviv University Modern Compiler Design.
Timed Automata.
Type checking © Marcelo d’Amorim 2010.
INF 212 ANALYSIS OF PROG. LANGS Type Systems Instructors: Crista Lopes Copyright © Instructors.
1 Temporal Claims A temporal claim is defined in Promela by the syntax: never { … body … } never is a keyword, like proctype. The body is the same as for.
Introduction to Data Flow Graphs and their Scheduling Sources: Gang Quan.
CS 355 – Programming Languages
Type Checking.
Course on Probabilistic Methods in Concurrency (Concurrent Languages for Probabilistic Asynchronous Communication) Lecture 1 The pi-calculus and the asynchronous.
Foundations of Interaction ETAPS `05 0 Ex nihilo: a reflective higher- order process calculus The  -calculus L.G. Meredith 1 & Matthias Radestock.
DATAFLOW PROCESS NETWORKS Edward A. Lee Thomas M. Parks.
Chapter 7Louden, Programming Languages1 Chapter 7 - Control I: Expressions and Statements "Control" is the general study of the semantics of execution.
Ordering and Consistent Cuts Presented By Biswanath Panda.
1 Operational Semantics Mooly Sagiv Tel Aviv University Textbook: Semantics with Applications.
CS 536 Spring Global Optimizations Lecture 23.
Control Flow Analysis Mooly Sagiv Tel Aviv University Sunday Scrieber 8 Monday Schrieber.
CS 330 Programming Languages 09 / 18 / 2007 Instructor: Michael Eckmann.
Strict Bidirectional Type Checking Adam Chlipala, Leaf Petersen, and Robert Harper.
CSE 130 : Winter 2006 Programming Languages Ranjit Jhala UC San Diego Lecture 7: Polymorphism.
1 Ivan Lanese Computer Science Department University of Bologna Italy Concurrent and located synchronizations in π-calculus.
Semantics with Applications Mooly Sagiv Schrirber html:// Textbooks:Winskel The.
CS 330 Programming Languages 09 / 16 / 2008 Instructor: Michael Eckmann.
Operational Semantics Semantics with Applications Chapter 2 H. Nielson and F. Nielson
Program Analysis Mooly Sagiv Tel Aviv University Sunday Scrieber 8 Monday Schrieber.
1 Ivan Lanese Computer Science Department University of Bologna Italy Streaming Services in SSCC Joint work with Francisco Martins, Vasco Vasconcelos and.
Chapter 7Louden, Programming Languages1 Chapter 7 - Control I: Expressions and Statements "Control" is the general study of the semantics of execution.
Programming Languages 2nd edition Tucker and Noonan Chapter 6 Types I was eventually persuaded of the need to design programming notations so as to maximize.
Introduction to Data Flow Graphs and their Scheduling Sources: Gang Quan.
Prof. Bodik CS 164 Lecture 16, Fall Global Optimization Lecture 16.
1 Type-Directed Concurrency Deepak Garg, Frank Pfenning {dg+, Carnegie Mellon University.
Fundamentals of Python: From First Programs Through Data Structures
Cheng/Dillon-Software Engineering: Formal Methods Model Checking.
Fundamentals of Python: First Programs
1 Static Type Analysis of Path Expressions in XQuery Using Rho-Calculus Wang Zhen (Selina) Oct 26, 2006.
CS6133 Software Specification and Verification
An Effective Method to Control Interrupt Handler for Data Race Detection Makoto Higashi †, Tetsuo Yamamoto ‡, Yasuhiro Hayase †, Takashi Ishio † and Katsuro.
Linear Type Systems for Concurrent Languages Eijiro Sumii Naoki Kobayashi University of Tokyo.
CS 363 Comparative Programming Languages Semantics.
Programming Languages 2nd edition Tucker and Noonan Chapter 6 Type Systems I was eventually persuaded of the need to design programming notations so as.
Chapter 3 Part II Describing Syntax and Semantics.
Languages and Compilers
Ivan Lanese Computer Science Department University of Bologna/INRIA Italy Decidability Results for Dynamic Installation of Compensation Handlers Joint.
Types and Programming Languages Lecture 11 Simon Gay Department of Computing Science University of Glasgow 2006/07.
CS533 – Spring Jeanie M. Schwenk Experiences and Processes and Monitors with Mesa What is Mesa? “Mesa is a strongly typed, block structured programming.
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
CSE 130 : Spring 2011 Programming Languages Ranjit Jhala UC San Diego Lecture 5: Functions and Closures.
Operational Semantics Mooly Sagiv Tel Aviv University Textbook: Semantics with Applications Chapter.
COMP 412, FALL Type Systems II C OMP 412 Rice University Houston, Texas Fall 2000 Copyright 2000, Robert Cartwright, all rights reserved. Students.
Operational Semantics Mooly Sagiv Tel Aviv University Sunday Scrieber 8 Monday Schrieber.
Operational Semantics Mooly Sagiv Reference: Semantics with Applications Chapter 2 H. Nielson and F. Nielson
Operational Semantics Mooly Sagiv Reference: Semantics with Applications Chapter 2 H. Nielson and F. Nielson
An Efficient Compilation Framework for Languages Based on a Concurrent Process Calculus Yoshihiro Oyama Kenjiro Taura Akinori Yonezawa Yonezawa Laboratory.
Code Optimization Overview and Examples
Type Checking and Type Inference
Formal verification in SPIN
Representation, Syntax, Paradigms, Types
Structural testing, Path Testing
User-Defined Functions
Chapter 6 Intermediate-Code Generation
Lecture 15 (Notes by P. N. Hilfinger and R. Bodik)
Information Security CS 526
Representation, Syntax, Paradigms, Types
Representation, Syntax, Paradigms, Types
Information Security CS 526
Presentation transcript:

A Generalized Deadlock-Free Process Calculus Eijiro Sumii Naoki Kobayashi University of Tokyo

Merit and Demerit of Concurrent Languages Compared with sequential languages... zMerit: more expressive power yInherently concurrent application (e.g. GUI) yParallel/distributed computation

Merit and Demerit of Concurrent Languages Compared with sequential languages... zMerit: more expressive power yInherently concurrent application (e.g. GUI) yParallel/distributed computation zDemerit: more complicated behavior  Non-determinism (possibility of various results)  Deadlock (failure of due communication)

Merit and Demerit of Concurrent Languages Compared with sequential languages... zMerit: more expressive power yInherently concurrent application (e.g. GUI) yParallel/distributed computation zDemerit: more complicated behavior  Non-determinism (possibility of various results)  Deadlock (failure of due communication) è Errors & inefficiencies

Example of Complication (1/2) In ML: f : int->int├ f(3) : int è eventually returns a unique result (unless ‘infinite loop’ or ‘side effect’)

Example of Complication (1/2) In CML: f : int->int├ f(3) : int è may return: ― different results in parallel (  non-determinism) fun f(i) = let val c : int chan = channel() in (spawn(fn () => send(c, i + 1)); spawn(fn () => send(c, i + 2)); recv(c)) end

Example of Complication (1/2) In CML: f : int->int├ f(3) : int è may return: ― different results in parallel (  non-determinism) ― no result at all (  deadlock) fun f(i) = let val c : int chan = channel() in recv(c) end

Example of Complication (2/2) Mutex channel m : unit chan zcorrect use: ― receive once, send once recv(m); CriticalSection ; send(m, ())

Example of Complication (2/2) Mutex channel m : unit chan zcorrect use: ― receive once, send once zincorrect use: ― receive once, send never (  deadlock) recv(m); CS ; () ― receive once, send twice (  non-determinism) recv(m); CS ; send(m, ()); send(m, ());

Example of Complication (2/2) Mutex channel m, n : unit chan zcorrect use: ― receive once, send once zincorrect use: ― receive once, send never (  deadlock) ― receive once, send twice (  non-determinism) ― use in various order (  deadlock) spawn(fn () => recv(m); recv(n); …); spawn(fn () => recv(n); recv(m); …)

Possible Approaches zProvide higher-level constructs e.g.: ― parallel functions ― binary semaphores ― concurrent objects

Possible Approaches zProvide higher-level constructs e.g.: ― parallel functions ― binary semaphores ― concurrent objects 8 “chaos” outside them 8 complicated syntax & semantics

Possible Approaches zProvide higher-level constructs 8 “chaos” outside them 8 complicated syntax & semantics zEnrich channel types: control communication with a static type system

Possible Approaches zProvide higher-level constructs 8 “chaos” outside them 8 complicated syntax & semantics zEnrich channel types: control communication with a static type system  Our approach

Outline zIntroduction zBasic Ideas zThe Type System zRelated Work zConclusion

Target Language Asynchronous variant of Milner’s  -calculus  new x in P (channel creation)  x![y] (output)  x?[y].P (input)  P | Q (parallel execution)  def x[y]=P in Q (process definition)  if x then P else Q (conditional branch)

Target Language Asynchronous variant of Milner’s  -calculus  new x in P (channel creation)  x![y] (output)  x?[y].P (input)  P | Q (parallel execution)  def x[y]=P in Q (process definition)  if x then P else Q (conditional branch) ― x?[y].P | x![z]  P { z / y } ― def x[y]=P in x![z]  def x[y]=P in P { z / y }

Outline zIntroduction zBasic Ideas  Usages & Usage Calculus  “In what way each channel may be used”  Time Tags & Time Tag Ordering  “In what order those channels may be used” zThe Type System zRelated Work zConclusion

Usages (1/2): Input/Output  U (usage) :=  O (output)  I. U(input + sequential execution)  U | V(parallel execution)   (none) 4 x:[]/(O|I)├ x![] | x?[] 8 x:[]/(O|I)├ x![] | x![] | x?[] | x?[]

Usages (1/2): Input/Output  U (usage) :=  O (output)  I. U(input + sequential execution)  U | V(parallel execution)   (none) 4 y:[]/(O|O|I.I)├ y![] | y![] | y?[].y?[] 8 y:[]/(O|O|I.I)├ y![] | y![] | y?[] | y?[]

Usages (2/2): Obligation and Capability  U (usage) :=  O a (output)  I a. U(input + sequential execution) y…  a (attributes) :=  (none)  o (obligation: “must be performed”)  c (capability: “can be performed successfully”)  co (both)

Usages (2/2): Obligation and Capability x:[int]/Oo “must send an integer value to x ” 4 x:[int]/Oo├ x![3] 8 x:[int]/Oo├ 0

Usages (2/2): Obligation and Capability y:[int]/Ic “can receive an integer value from y successfully” 4 y:[int]/Ic├ y?[v].0  eventually reduces to 0 (by communication with an external process) 4 y:[int]/Ic├ 0

Usages (2/2): Obligation and Capability What to Ensure: zAn obligation must be fulfilled eventually zA capability can be used successfully  Otherwise “deadlock”

Reliability of Usages & the Usage Calculus 8 new x:[int]/Ic in x?[v].P

Reliability of Usages & the Usage Calculus 8 new x:[int]/Ic in x?[v].P “For every I/O with capability, a corresponding O/I with obligation” 4 new x:[int]/(Ic|Oo) in (x?[v].P | x![3])

Reliability of Usages & the Usage Calculus “For every I/O with capability, a corresponding O/I with obligation” 8 new x:[]/(Oo|Ic|Ic) in (x![] | x?[].P | x?[].Q)  new x:[]/Ic in x?[].Q

Reliability of Usages & the Usage Calculus “For every I/O with capability, a corresponding O/I with obligation” 8 new x:[]/(Oo|Ic|Ic) in (x![] | x?[].P | x?[].Q)  new x:[]/Ic in x?[].Q Oo|Ic|Ic  Ic

Outline zIntroduction zBasic Ideas  Usages & Usage Calculus  “In what way each channel may be used”  Time Tags & Time Tag Ordering  “In what order those channels may be used” zThe Type System zRelated Work zConclusion

Dependency between Obligation and Capability 4 x:[int]/Oo├ x![3] 8 y:[]/I, x:[int]/Oo├ y?[].x![3] 4 y:[]/Ic, x:[int]/Oo├ y?[].x![3]

Dependency between Obligation and Capability t<s “a capability with t may be used before an obligation with s is fulfilled” 4 y:[]/Ic t, x:[int]/Oo s ; t<s├ y?[].x![3] 8 y:[]/Ic t, x:[int]/Oo s ;  ├ y?[].x![3] 8 y:[]/Ic t, x:[int]/Oo s ; s<t├ y?[].x![3]

Preventing & Detecting Cycles in the Dependency  = c:[]/(Oo s |Ic s ), d:[]/(Oo t |Ic t ) 4  ; s<t├ c?[].d![] |... 8  ; s<t├ d?[].c![] |...

Preventing & Detecting Cycles in the Dependency  = c:[]/(Oo s |Ic s ), d:[]/(Oo t |Ic t ) 4  ; s<t├ c?[].d![] |... 8  ; s<t├ d?[].c![] |... 4  ; t<s├ d?[].c![] |... 8  ; t<s├ c?[].d![] |...

Preventing & Detecting Cycles in the Dependency  = c:[]/(Oo s |Ic s ), d:[]/(Oo t |Ic t ) 8  ; s<t├ c?[].d![] | d?[].c![] 8  ; t<s├ c?[].d![] | d?[].c![]  ; s<t,t<s├ c?[].d![] | d?[].c![]

Outline zIntroduction zBasic Ideas zThe Type System yType Judgment & Typing Rules yCorrectness & Expressiveness yType Checking zRelated Work zConclusion

Type Judgment  ;  ├ P   : type environment (mapping from variables to types)   : time tag ordering (binary relation on time tags) P uses communication channels according to: ― the usage specified by  ― the order specified by 

Example of Typing Rules T-Out (simplified):  includes obligations ⇒ a includes capability s < time tags on obligations included in   includes no obligation ───────────────────  + x:[  ]/O a s + y:  ; <├ x![y]

Example of Typing ret :[ int ]/Oo u ;  ├ def fib [i: int,r:[ int ]/Oo s ] = if i<2 then r![1] else new c:[ int ]/(Oo t |Oo t |Ic t.Ic t ) in ( fib ![i-1,c] | fib ![i-2,c] | c?[j].c?[k].r![j+k]) in fib ![10, ret ]

Example of Typing ret :[ int ]/Oo u ;  ├ def fib [i: int,r:[ int ]/Oo s ] = if i<2 then r![1] else new c:[ int ]/(Oo t |Oo t |Ic t.Ic t ) in ( fib ![i-1,c] | fib ![i-2,c] | c?[j].c?[k].r![j+k]) in fib ![10, ret ]

Example of Typing ret :[ int ]/Oo u ;  ├ def fib [i: int,r:[ int ]/Oo s ] = if i<2 then r![1] else new c:[ int ]/(Oo t |Oo t |Ic t.Ic t ) in ( fib ![i-1,c] | fib ![i-2,c] | c?[j].c?[k].r![j+k]) in fib ![10, ret ]

Example of Typing ret :[ int ]/Oo u ;  ├ def fib [i: int,r:[ int ]/Oo s ] = if i<2 then r![1] else new c:[ int ]/(Oo t |Oo t |Ic t.Ic t ) in ( fib ![i-1,c] | fib ![i-2,c] | c?[j].c?[k].r![j+k]) in fib ![10, ret ]

Outline zIntroduction zBasic Ideas zThe Type System yType Judgment & Typing Rules yCorrectness & Expressiveness yType Checking zRelated Work zConclusion

Correctness of the Type System No immediate deadlock: Well-typed processes are not in deadlock

Correctness of the Type System No immediate deadlock: Well-typed processes are not in deadlock + Subject reduction: Well-typedness is preserved by reduction

Correctness of the Type System No immediate deadlock: Well-typed processes are not in deadlock + Subject reduction: Well-typedness is preserved by reduction  Deadlock-freedom: Well-typed processes never fall into deadlock throughout reduction

Correctness of the Type System Deadlock-freedom: (the case of an output obligation)   + x:[  ]/O o t ;  ├ P  Every usage in  + x:[  ]/O o t is reliable z  + is a strict partial order  P will eventually perform output on x (unless ‘infinite loop’)

Expressiveness of the Calculus Expressive enough to encode: yParallel functions yTypical concurrent objects yVarious semaphores

Expressiveness of the Calculus Expressive enough to encode: yParallel functions yTypical Concurrent Objects yVarious Semaphores Too conservative to express: yCase-by-case dependency c:[]/(I co s |O co s ), d:[]/(I co t |O co t ); s<t,t<s├ c![] | d![] | if … then c?[].….d?[].… else d?[].….c?[].…

Outline zIntroduction zBasic Ideas zThe Type System yType Judgment & Typing Rules yCorrectness & Expressiveness yType Checking zRelated Work zConclusion

Issues in Type Checking zUsages of channels: must be explicitly specified by programmers zReliability of usages: can be automatically checked (by a co-inductive method) zTime tag ordering: can be automatically inferred (by generation & satisfaction of constraints)

Outline zIntroduction zBasic Ideas zThe Type System zRelated Work zConclusion

Related Work (1/4) [Kobayashi 97] Partially deadlock-free typed process calculus zIn what way each channel may be used yLinear Channels (used just once for communication) yMutex Channels (used like binary semaphores) yReplicated Input Channels (used for process definition) zIn what order those channels may be used ― Time tags and their ordering

Related Work (2/4) [Pierce & Sangiorgi 93] I/O Types: In what direction a channel may be used (for input, for output, or for both) c:  [ int ] ⇔ c:[ int ]/!O [Kobayashi & Pierce & Turner 96] Linear Types: How many times a channel may be used (once or unlimitedly) c:  1 [ int ] ⇔ c:[ int ]/(O co |I co )

Related Work (3/4) [Yoshida 96] Graph Types: In what order processes perform input/output on channels ― Only ‘capability + obligation’; cannot express ‘capability without obligation’ and ‘obligation without capability’

Related Work (4/4) [Boudol 97] Hennessy-Milner logic with recursion: On what channels processes are ready to receive values ― Deadlock-freedom only for output; cannot guarantee deadlock-freedom for input

Outline zIntroduction zBasic Ideas zThe Type System zRelated Work zConclusion

Conclusion (1/2): Summary Static type system that prevents deadlock: zUsages & Usage Calculus “In what way each channel is used” + zTime Tags & Time Tag Ordering “In what order those channels are used”

Conclusion (2/2): Future Work zDevelop a (partial) type inference algorithm zApply to practical concurrent languages zUtilize for compile-time optimization Prototype type checker available at: /~sumii/pub/