kill safe synchronization abstractions
play

Kill-Safe Synchronization Abstractions Matthew Flatt Robert Bruce - PowerPoint PPT Presentation

Kill-Safe Synchronization Abstractions Matthew Flatt Robert Bruce Findler University of Utah University of Chicago 1 Sibling Food-Sharing Protocol 2 Sibling Food-Sharing Protocol 3 Sibling Food-Sharing Protocol 4 Sibling Food-Sharing


  1. Kill-Safe Synchronization Abstractions Matthew Flatt Robert Bruce Findler University of Utah University of Chicago 1

  2. Sibling Food-Sharing Protocol 2

  3. Sibling Food-Sharing Protocol 3

  4. Sibling Food-Sharing Protocol 4

  5. Sibling Food-Sharing Protocol 5

  6. Sibling Food-Sharing Protocol 6

  7. Sibling Food-Sharing Protocol 7

  8. Sibling Food-Sharing Protocol • By inspection, the protocol is fair • No parental supervision required 8

  9. Sharing among Processes 9

  10. Sharing among Processes 10

  11. Sharing among Processes 11

  12. Sharing among Processes 12

  13. Sharing among Processes • Queue should be safe and fair • Should require no kernel supervision 13

  14. Sharing in Java synchronized 14

  15. Sharing in Java synchronized Thread.stop ⇒ synchronized isn't enough 15

  16. Sharing in Java synchronized Thread.stop ⇒ synchronized isn't enough 16

  17. Sharing in Java synchronized ... Thread.stop ⇒ synchronized isn't enough 17

  18. Sharing in Java synchronized ... Thread.stop ⇒ synchronized isn't enough ∴ Java has no Thread.stop 18

  19. Why Terminate? • Execute code in a programming environment (DrScheme) 19

  20. Why Terminate? • Execute code in a programming environment (DrScheme) • Cancel actions that allocate resources (HTML browser) 20

  21. Why Terminate? • Execute code in a programming environment (DrScheme) • Cancel actions that allocate resources (HTML browser) • Stop misbehaving servlets (web server) 21

  22. Building Kill-Safe Abstractions abstraction abstraction thread-safe thread-safe abstraction abstraction kill-safe kill-safe thread-safe thread-safe abstraction abstraction 22

  23. Building Kill-Safe Abstractions abstraction abstraction Programmer effort — but generally understood thread-safe thread-safe abstraction abstraction kill-safe kill-safe thread-safe thread-safe abstraction abstraction 23

  24. Building Kill-Safe Abstractions abstraction abstraction Programmer effort — but generally understood thread-safe thread-safe abstraction abstraction Programmer effort kill-safe kill-safe — the subject of this talk thread-safe thread-safe abstraction abstraction 24

  25. Building Kill-Safe Abstractions abstraction abstraction Start with Concurrent ML [Reppy 88] thread-safe thread-safe abstraction abstraction kill-safe kill-safe thread-safe thread-safe abstraction abstraction 25

  26. Building Kill-Safe Abstractions abstraction abstraction Start with Concurrent ML [Reppy 88] thread-safe thread-safe abstraction abstraction Add MzScheme's custodians kill-safe kill-safe and a little more thread-safe thread-safe abstraction abstraction 26

  27. Sharing in Concurrent ML 27

  28. Sharing in Concurrent ML 28

  29. Sharing in Concurrent ML 29

  30. Sharing in Concurrent ML Abstraction-as-process naturally supports termination 30

  31. Sharing in Concurrent ML Abstraction-as-process naturally supports termination Remaining problem: who controls the abstraction's process? 31

  32. Managing Processes and Threads 32

  33. Managing Processes and Threads 33

  34. Managing Processes and Threads = custodian = capability to execute 34

  35. Managing Processes and Threads = custodian = capability to execute 35

  36. Managing with Custodians 36

  37. Managing with Custodians 37

  38. Managing with Custodians 38

  39. Managing with Custodians 39

  40. Managing with Custodians Queue terminated with servlet 40

  41. Thread-Safe Abstractions A language to support abstractions: • Concurrent ML primitives for thread communication • Custodians for process hierarchy Each abstraction: • Manager thread for state 41

  42. Towards Kill Safety with Custodians 42

  43. Towards Kill Safety with Custodians 43

  44. Towards Kill Safety with Custodians Not kill-safe among servlets 44

  45. Kill Safety through Joint Custody 45

  46. Kill Safety through Joint Custody 46

  47. Kill Safety through Joint Custody 47

  48. Kill Safety through Joint Custody 48

  49. Kill Safety through Joint Custody Queue runs exactly as long as servlets 49

  50. Why a Thread can have Multiple Custodians 50

  51. Why a Thread can have Multiple Custodians 51

  52. Why a Thread can have Multiple Custodians 52

  53. Why a Thread can have Multiple Custodians 53

  54. Why a Thread can have Multiple Custodians 54

  55. Why a Thread can have Multiple Custodians Queue is only mostly dead 55

  56. Why a Thread can have Multiple Custodians Queue is only mostly dead 56

  57. Why a Thread can have Multiple Custodians Use queue ⇒ grant custodian 57

  58. Kill-Safe Abstractions A language to support abstractions: • Concurrent ML primitives for thread communication • Custodians for process hierarchy • Operation to grant a thread another custodian Each abstraction: • Manager thread for state • Each action grants custodian to manager thread 58

  59. Non-Solution #1 — Atomic Region = atomic 59

  60. Non-Solution #1 — Atomic Region Queue might harm = atomic other servlets 60

  61. Non-Solution #2 — Disjoint Process 61

  62. Non-Solution #2 — Disjoint Process 62

  63. Non-Solution #2 — Disjoint Process 63

  64. Non-Solution #2 — Disjoint Process Queue runs forever 64

  65. Non-Solution #3 — Meta-Servlet 65

  66. Non-Solution #3 — Meta-Servlet Merely moves the “kernel” 66

  67. Solution — Joint Custody 67

  68. Details (See Paper) • Custodians granted through thread-resume • CML's guard-evt a natural place for thread-resume • Improved nack-guard-evt for two-step protocols • Kill-safe does not always imply break-safe, nor vice-versa 68

  69. A Thread-Safe Queue (define-struct safe-q (define (safe-get sq) (put-ch get-ch)) (channel-recv (safe-q-get-ch sq))) (define (safe-queue) (define q (queue)) (define (safe-put sq v) (define get-ch (channel)) (channel-send (define put-ch (channel)) (safe-q-put-ch sq) v)) (define (q-loop) (sync (choice-evt (wrap-evt (channel-send get-ch (peek q)) (lambda () (get q))) (wrap-evt (channel-recv put-ch) (lambda (v) (put q v))))) (q-loop)) (spawn q-loop) (make-safe-q put-ch get-ch)) 69

  70. A Kill-Safe Queue (define-struct safe-q (define (safe-get sq) (manager-t put-ch get-ch)) (resume sq) (channel-recv (define (safe-queue) (safe-q-get-ch sq))) (define q (queue)) (define get-ch (channel)) (define (safe-put sq v) (define put-ch (channel)) (resume sq) (define (q-loop) (channel-send (sync (safe-q-put-ch sq) v)) (choice-evt (wrap-evt (define (resume sq) (channel-send get-ch (peek q)) (thread-resume (lambda () (get q))) (safe-q-manager-t sq) (wrap-evt (current-thread))) (channel-recv put-ch) (lambda (v) (put q v))))) (q-loop)) (define manager-t (spawn q-loop)) (make-safe-q manager-t put-ch get-ch)) 70

Recommend


More recommend