Processes without Partitions Matthew Flatt University of Utah Adam Wick Robert Bruce Findler University of Utah University of Chicago 1
This talk has been modified from its original version. It has been edited for content and formatted to fit your screen. 2
Machines and Processes 3
Machines and Processes 101010 010101 4
Machines and Processes 101010 010101 5
Machines and Processes λ λ 101010 010101 6
Machines and Processes λ λ OS 101010 010101 7
Machines and Processes λ λ VM 101010 010101 8
Process Examples 9
Process Examples 10
Process Examples 11
Process Examples 12
Process Examples λ λ DrScheme user's program Run DrScheme 13
Languages with Termination Pilot [Redell80] SPIN [Bershad95] JKernel [Hawblitzel98] Alta [Tullman99] KaffeOS [Back00] JSR-121 [Soper03] .NET application domains ... λ λ 14-15
Languages with Termination PLT Scheme λ λ 16
Motivation and Approach Processes in PLT Scheme • Threads • Parameters • Eventspaces • Custodians Memory Accounting 17
Threads Concurrent execution eval (require "spin-display.scm") (define (spin) (rotate-a-little) (sleep 0.1) (spin)) eval (define spinner (thread spin)) eval (kill-thread spinner) 18
Parameters (a.k.a. Fluid Variables) Thread-local state (printf "Hello\n") (fprintf (current-output-port) "Hola\n") (fprintf (current-error-port) "Goodbye\n") eval (error "Ciao") (parameterize ((current-error-port (current-output-port))) eval (error "Au Revoir")) (parameterize ((current-error-port (current-output-port))) (thread (lambda () eval (error "Zai Jian")))) 19
Eventspaces Concurrent GUIs (thread (lambda () (message-box "One" "Hi"))) eval (thread (lambda () (message-box "Two" "Bye"))) (thread (lambda () (message-box "One" "Hi"))) (parameterize ((current-eventspace (make-eventspace))) eval (thread (lambda () (message-box "Two" "Bye")))) 20
Custodians Termination and clean-up (define c (make-custodian)) (parameterize ((current-custodian c)) eval ...) eval (custodian-shutdown-all c) 21
Etc. • Security Guards Resource access control • Namespaces Global bindings • Will Executors Timing of finalizations • Inspectors Debugging access 22
Building a Programming Environment SchemeEsq, a mini DrScheme [ICFP 99] 23
GUI - Frame (define frame (new frame% [label "SchemeEsq"] [width 400] [height 175])) (send frame show #t) eval 24
GUI - Reset Button (new button% [label "Reset"] [parent frame] [callback (lambda (b e) (reset-program))]) eval 25
GUI - Interaction Area (define repl-display-canvas (new editor-canvas% [parent frame])) eval 26
GUI - Interaction Buffer (define esq-text% (class text% ... (evaluate str) ...)) (define repl-editor (new esq-text%)) (send repl-display-canvas set-editor repl-editor) eval 27
Evaluator (define (evaluate expr-str) (thread (lambda () (print (eval (read (open-input-string expr-str)))) (newline) (send repl-editor new-prompt)))) eval 28
Evaluator Output (define user-output-port (make-output-port ... repl-editor ...)) (define (evaluate expr-str) (parameterize ((current-output-port user-output-port)) (thread (lambda () ...)))) eval 29
Evaluating GUIs (define user-eventspace (make-eventspace)) (define (evaluate expr-str) (parameterize ((current-output-port user-output-port) (current-eventspace user-eventspace)) (thread (lambda () ...))) eval 30
Custodian for Evaluation (define user-custodian (make-custodian)) (define user-eventspace (parameterize ((current-custodian user-custodian)) (make-eventspace))) (define (evaluate expr-str) (parameterize ((current-output-port user-output-port) (current-eventspace user-eventspace) (current-custodian user-custodian)) (thread (lambda () ...)))) eval 31
Reset Evaluation (define (reset-program) (custodian-shutdown-all user-custodian) (set! user-custodian (make-custodian)) (parameterize ((current-custodian user-custodian)) (set! user-eventspace (make-eventspace))) (send repl-editor reset)) eval 32
Motivation and Approach Processes in PLT Scheme Memory Accounting • Without partitions [ISMM 04] 33
Resource Consumption λ λ DrScheme user's program 34
Resource Consumption λ λ DrScheme user's program 35
Resource Consumption λ λ DrScheme user's program 36
Resource Consumption λ λ DrScheme user's program 37
Resource Consumption λ λ DrScheme user's program 38
Resource Consumption λ λ DrScheme user's program 39
Resource Accounting • Conventional OS : process memory use = size of partition λ λ Accounting is easy Trading data is difficult 40
Resource Accounting • Language as OS : process memory use = size of owned data λ λ Trading data is easy Accounting appears difficult: sharing, real-time tracking 41
Resource Accounting Our strategy: compute accounting charges during GC λ λ See also [Price03] 42
Basic Accounting thread 1 x q = custodian A λ thread 2 y r = custodian B λ z s thread 3 43
Basic Accounting A A thread 1 x q = custodian A λ A A thread 2 y r = custodian B λ z s thread 3 B B 44
Basic Accounting A A thread 1 x q = custodian A λ A A thread 2 y r = custodian B λ z s thread 3 B, A B, A 45
Sharing = custodian A thread 1 λ x z y = custodian B thread 2 λ 46
Sharing A = custodian A thread 1 λ x A or B z y = custodian B thread 2 λ B 47
Sharing: Charge the Child A = custodian A thread 1 λ x B, A z y = custodian B thread 2 λ B 48
Threads, Custodians, and Weak References = custodian A thread 1 λ x = custodian B thread 2 λ 49
Threads, Custodians, and Weak References = custodian A thread 1 λ B x = custodian B thread 2 λ 50
Threads, Custodians, and Weak References = custodian A thread 1 λ B x = custodian B thread 2 λ 51
Threads, Custodians, and Weak References = custodian A thread 1 λ B x = custodian B thread 2 λ 52
Why Charge the Child? A = custodian A thread 1 λ x B, A z y = custodian B thread 2 λ B • Parent is responsible for children • Parent may allocate for children GUI objects File descriptors ... 53-55
Initial Experience: DrScheme Bad Loop Normal Normal 56
Initial Experience: DrScheme Bad Loop Normal Shut Down 57
DrScheme Bug = DrScheme thread 0 λ x = User1 thread 1 y λ z = User2 thread 2 λ 58
DrScheme Repair = DrScheme thread 0 λ x = User1 thread 1 y λ z = User2 thread 2 λ 59
DrScheme Repair = DrScheme thread 0 λ x = User1 thread 1 y λ z = User2 thread 2 λ Changed 5 references: • Weakened 2 • Removed 2 • Moved 1 into child 60
Current Experience: DrScheme Bad Loop Normal Normal 61
Current Experience: DrScheme Shut Down Normal Normal 62
Accounting without Partitions Useful accounting • Doesn't need partitions • Does need hierarchy 63
Conclusion λ λ • Programmers need OS-like constructs in languages concurrency adjust run-time environment easy termination • Multiple language constructs for “process” programmer can mix and match to balance isolation and cooperation 64
Recommend
More recommend