34
UNIVERSITY OF NIVERSITY OF MASSACHUSETTS ASSACHUSETTS, A , AMHERST MHERST Department of Computer Science Department of Computer Science Multilisp: Concurrent Functional Programming Ed Walters and Tim Richards University of Massachusetts Amherst

Multilisp: Concurrent Functional Programming

  • Upload
    janae

  • View
    48

  • Download
    0

Embed Size (px)

DESCRIPTION

Ed Walters and Tim Richards University of Massachusetts Amherst. Multilisp: Concurrent Functional Programming. Overview. What is Multilisp? Overview of Scheme Features of Multilisp Where is Multilisp Now?. Overview. What is Multilisp? Overview of Scheme Features of Multilisp - PowerPoint PPT Presentation

Citation preview

Page 1: Multilisp: Concurrent Functional Programming

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science

Multilisp: Concurrent Functional Programming

Ed Walters and Tim Richards

University of Massachusetts Amherst

Page 2: Multilisp: Concurrent Functional Programming

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 2

Overview What is Multilisp? Overview of Scheme Features of Multilisp Where is Multilisp Now?

Page 3: Multilisp: Concurrent Functional Programming

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 3

Overview What is Multilisp? Overview of Scheme Features of Multilisp Where is Multilisp Now?

Page 4: Multilisp: Concurrent Functional Programming

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 4

What is Multilisp? Dialect of Scheme language

Functional Programming Limited Side-effects Garbage Collection

Extensions for Concurrency Parallel Function Application Futures

Reference: R. Halstead, TOPLAS, Vol. 7, No. 4, 1985.

Page 5: Multilisp: Concurrent Functional Programming

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 5

Goal of Multilisp Explicit Constructs for Concurrency Adhere to Scheme Philosophy

No Additional Syntax Minimal Additional Semantics Maximum Flexibility

Granularity Backwards-compatibility

Page 6: Multilisp: Concurrent Functional Programming

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 6

Overview What is Multilisp? Overview of Scheme Features of Multilisp Where is Multilisp Now?

Page 7: Multilisp: Concurrent Functional Programming

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 7

The Scheme Language

Descendent of Lisp (LISt Processing)

Created by Steele and Sussman (1975)

Important Features: Extended Lambda Calculus Lexical Scoping Functions are first-class

Page 8: Multilisp: Concurrent Functional Programming

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 8

Important Terms Expression: Basic unit of Scheme

code (e.g., List or integer) Evaluation: Scheme expressions

evaluate to a value upon execution Application: Function call on a list,

i.e. apply first element to rest of list (f a b c) => f(a, b, c)

Page 9: Multilisp: Concurrent Functional Programming

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 9

Brief Scheme Syntax Function definition

(define f (lambda (x) … )) Function application

(f x) Conditionals

(if x y z) Symbols and Atomic Elements

‘x, 3

Page 10: Multilisp: Concurrent Functional Programming

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 10

Scheme Example: Fib

(define fib (lambda (x)

(if (= x 1) 1(if (= x 2) 2

(+ (fib (- x 1)) (fib (- x 2)))))))

(fib 10) => 89

Page 11: Multilisp: Concurrent Functional Programming

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 11

Scheme Example: Fib

(define fib (lambda (x)

(if (= x 1) 1(if (= x 2) 2

(+ (fib (- x 1)) (fib (- x 2)))))))

(fib 10) => 89

Page 12: Multilisp: Concurrent Functional Programming

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 12

Scheme Example: Fib

(define fib (lambda (x)

(if (= x 1) 1(if (= x 2) 2

(+ (fib (- x 1)) (fib (- x 2)))))))

(fib 10) => 89

Page 13: Multilisp: Concurrent Functional Programming

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 13

Scheme Example: Fib

(define fib (lambda (x)

(if (= x 1) 1(if (= x 2) 2

(+ (fib (- x 1)) (fib (- x 2)))))))

(fib 10) => 89

Page 14: Multilisp: Concurrent Functional Programming

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 14

Scheme Example: Fib

(define fib (lambda (x)

(if (= x 1) 1(if (= x 2) 2

(+ (fib (- x 1)) (fib (- x 2)))))))

(fib 10) => 89

Page 15: Multilisp: Concurrent Functional Programming

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 15

Scheme Example: Fib

(define fib (lambda (x)

(if (= x 1) 1(if (= x 2) 2

(+ (fib (- x 1)) (fib (- x 2)))))))

(fib 10) => 89

Page 16: Multilisp: Concurrent Functional Programming

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 16

Scheme Example: Fib

(define fib (lambda (x)

(if (= x 1) 1(if (= x 2) 2

(+ (fib (- x 1)) (fib (- x 2)))))))

(fib 10) => 89

Page 17: Multilisp: Concurrent Functional Programming

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 17

Overview What is Multilisp? Overview of Scheme Features of Multilisp Where is Multilisp Now?

Page 18: Multilisp: Concurrent Functional Programming

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 18

Parallel Calls pcall: Parallel function application Syntax: (pcall F A B C) Semantics:

Evaluate F, A, B, C in parallel Apply F to A, B, C

(F A B C)

Page 19: Multilisp: Concurrent Functional Programming

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 19

Parallel Calls: Example

(define div-and-conq

(lambda (x)

(if (base-case x) x

(pcall combine-results

(div-and-conq (- x 1))

(div-and-conq (- x 5))))))

Page 20: Multilisp: Concurrent Functional Programming

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 20

Parallel Calls: Example

(define div-and-conq

(lambda (x)

(if (base-case x) x

(pcall combine-results

(div-and-conq (- x 1))

(div-and-conq (- x 5))))))

Page 21: Multilisp: Concurrent Functional Programming

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 21

Parallel Calls: Example

(define div-and-conq

(lambda (x)

(if (base-case x) x

(pcall combine-results

(div-and-conq (- x 1))

(div-and-conq (- x 5))))))

Page 22: Multilisp: Concurrent Functional Programming

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 22

Parallel Calls: Example

(define div-and-conq

(lambda (x)

(if (base-case x) x

(pcall combine-results

(div-and-conq (- x 1))

(div-and-conq (- x 5))))))

Page 23: Multilisp: Concurrent Functional Programming

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 23

Parallel Calls: Example

(define div-and-conq

(lambda (x)

(if (base-case x) x

(pcall combine-results

(div-and-conq (- x 1))

(div-and-conq (- x 5))))))

Page 24: Multilisp: Concurrent Functional Programming

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 24

Futures future: contract to deliver parallel

computation Syntax: (future <exp>) Semantics:

Evaluate <exp> concurrently with calling program

Return reference to future immediately

Block if value of <exp> is required

Page 25: Multilisp: Concurrent Functional Programming

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 25

Futures: Example(define fib

(lambda (x) (if (= x 1) 1

(if (= x 2) 2(+ (future (fib (- x 1))) (future (fib (- x 2)))) ))))

(fib 10) => 89

Page 26: Multilisp: Concurrent Functional Programming

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 26

Futures: Example(define fib

(lambda (x) (if (= x 1) 1

(if (= x 2) 2(+ (future (fib (- x 1))) (future (fib (- x 2)))) ))))

(fib 10) => 89

Page 27: Multilisp: Concurrent Functional Programming

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 27

Futures: Example(define fib

(lambda (x) (if (= x 1) 1

(if (= x 2) 2(+ (future (fib (- x 1))) (future (fib (- x 2)))) ))))

(fib 10) => 89

Page 28: Multilisp: Concurrent Functional Programming

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 28

Futures: Example(define fib

(lambda (x) (if (= x 1) 1

(if (= x 2) 2(+ (future (fib (- x 1))) (future (fib (- x 2)))) ))))

(fib 10) => 89

Page 29: Multilisp: Concurrent Functional Programming

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 29

Futures: Example(define fib

(lambda (x) (if (= x 1) 1

(if (= x 2) 2(+ (future (fib (- x 1))) (future (fib (- x 2)))) ))))

(fib 10) => 89

Page 30: Multilisp: Concurrent Functional Programming

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 30

More Details pcall can be implemented using future Facilitates multiple concurrent

programming paradigms: Cilk-style Message Passing

Futures somewhat resemble Lazy Evaluation Evaluation delayed but guaranteed No infinite data structures

Page 31: Multilisp: Concurrent Functional Programming

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 31

Implementation Notes

Each future/pcall element is a thread

pcall fork/join parallelism

future asynchronous thread block on read

Page 32: Multilisp: Concurrent Functional Programming

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 32

Overview What is Multilisp? Overview of Scheme Features of Multilisp Where is Multilisp Now?

Page 33: Multilisp: Concurrent Functional Programming

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 33

Where is Multilisp Now?

No current Scheme compilers implement futures We had to implement our own interpreter!

However: THEY LIVE on in Java! Transparent Proxies for Java Futures,

Pratikakis, Spacco, and Hicks, OOPSLA 2004.

Safe Futures for Java, Welc, Jagannathan, and Hosking, OOPSLA 2005.

Page 34: Multilisp: Concurrent Functional Programming

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 34

Conclusion Like much of the Scheme World:

Elegant, Flexible Solution Deader than a Doornail Not Java