kappa insights status and future work
play

Kappa: Insights, Status and Future Work Elias Castegren , Tobias - PowerPoint PPT Presentation

Kappa: Insights, Status and Future Work Elias Castegren , Tobias Wrigstad IWACO16 sa Structured Aliasing Kappa: Insights, Status and Future Work Elias Castegren , Tobias Wrigstad IWACO16 sa Structured Aliasing Concurrency Imposes


  1. Kappa: Insights, Status and Future Work Elias Castegren , Tobias Wrigstad IWACO’16 sa Structured Aliasing

  2. Kappa: Insights, Status and Future Work Elias Castegren , Tobias Wrigstad IWACO’16 sa Structured Aliasing

  3. Concurrency Imposes Many Concerns Is it accessed concurrently? Is it aliased? Is it thread-safe? List l = … ; l.add(x); Does it encapsulate its Are its subtypes Is representation? thread-safe? synchronisation implicit or explicit?

  4. Aliasing and Concurrency Control assert c1.value() == 42; c1.inc(); May alias? c2.inc(); assert c1.value() == 43;

  5. Aliasing and Concurrency Control T 1 T 2 assert c1.value() == 42; c1.inc(); c2.inc(); May alias? assert c1.value() == 43; Properly Wasteful if unaliased! synchronised? Locking too much leads to other problems Lock EVERYONE!

  6. Reference Capabilities • A capability grants access to some resource object reference • The type of a capability defines the interface to its object • A capability assumes exclusive access Thread-safety ⇒ No data-races • How thread-safety is achieved is 
 controlled by the capability’s mode x : linear T

  7. Modes of Concurrency Control • Exclusive modes linear Globally unique thread Thread-local • Safe modes ! read locked Precludes mutating Implicit locking aliases

  8. ⎭ Modes of Concurrency Control Dominating modes ⎫ linear Guarantees ⎬ thread mutual exclusion locked Subordinate mode read subordinate Precludes mutating Encapsulated aliases

  9. Capability = Trait + Mode • Capabilities are introduced via traits trait Inc trait Get require var cnt : int require val cnt : int def inc() : void def value() : int this .cnt++ return this .cnt; • Modes control why they are safe linear Inc — Globally unique increment capability locked Inc — Implicitly synchronised increment capability read Inc — A read-only increment capability read Get — A read-only capability for getting the value

  10. Classes are Composed by C apabilities linear thread locked read subordinate class Counter = Inc ⊕ Get { var cnt : int }

  11. Aliasing and Concurrency Control (revisited) class LocalCounter = thread Inc ⊕ read Get May not alias! T 1 T 2 assert c1.value() == 42; c1.inc(); c2.inc(); assert c1.value() == 43; Properly synchronised! class SharedCounter = locked Inc ⊕ read Get Implemented by a readers-writer lock

  12. Composite C apabilities • A capability disjunction A ⊕ B can be used as A or B , but not at the same time • Capabilities that do not share data should be usable in parallel… trait Fst { trait Fst { trait Snd { trait Snd { require var fst : int require var fst : int require var snd : int require var snd : int … … … … } } } } class Pair = Fst ⊗ Snd { linear linear var fst : int var snd : int } • A capability conjunction A ⊗ B can be used as A and B , possibly in parallel

  13. Packing and Unpacking let p = new Pair(); let f, s = consume p; Fst Snd Fst Snd finish { async {f.set(x)} async {s.set(y)} } p = consume f + consume s p

  14. Packing and Unpacking let p = new Pair(); let f, s = consume p; Fst Snd finish { async {f.set(x)} async {s.set(y)} } p = consume f + consume s Fst Snd p f s

  15. Packing and Unpacking let p = new Pair(); let f, s = consume p; Fst Snd finish { async {f.set(x)} async {s.set(y)} } p = consume f + consume s Fst Snd p Fst Snd

  16. Kappa: Insights, Status and Future Work Elias Castegren , Tobias Wrigstad IWACO’16 sa Structured Aliasing

  17. Subordination and Trait-Based Reuse trait Add<T> • Reuse traits across di fg erent concurrency scenarios require var first : Link<T> def add(elem : T) : void • Separate business logic from concurrency concerns … subord this : subord Add<T> Can assume exclusive access Annotations in type declarations only class List<T> = Add<T> ⊕ … thread No e fg ect tracking var first : Link<T> or ownership types class SynchronizedList<T> = Add<T> ⊕ … locked var first : Link<T>

  18. Reference Capabilities as Primitives Ownership Inc ⊕ Get linear read External uniqueness Single writer, multiple readers read linear Inc ⊕ Get read Regions and e fg ects Left linear Inc ⊕ read Get class Tree = Left ⊗ Right ⊗ Elem left A var left : Tree Right var right : Tree … A ⊗ B var elem : int right multiple Elem disjoint elem writers B

  19. Kappa: Insights, Status and Future Work Elias Castegren , Tobias Wrigstad IWACO’16 sa Structured Aliasing

  20. Active Objects as a Mode of Synchronisation • The message queue of an active object can replace the synchronisation of locks Active by default class ActiveCounter var cnt : int def inc() : void this .cnt++ def get() : int return this .cnt class ActiveCounter = active Inc ⊕ active Get active active var cnt : int

  21. Active Objects as a Mode of Synchronisation • Opens up for new combinations ⊕ active linear Actor with unsynchronised initialisation methods ⊕ active locked Actor with priority channel ⊕ active subord Actor nested in another actor ⊗ active active Actor with parallel message queues

  22. Array Capabilities [A] A ⊗ B [A] [A] A B [A] [A ⊗ B] [B]

  23. A Hierarchy of Capabilities Capability Subordinate Exclusive Linear Thread Shared Safe Unsafe Pessimistic … Optimistic Oblivious Atomic Lock-Free Locked Active Read Immutable

  24. Conclusions • Reference capabilities is a promising approach for thread-safe OO programming • Brings together ideas from a wide variety of work in a unified system Ownership/Universe types 
 Linear/Unique references and external uniqueness 
 Read-only/Immutability 
 Regions and e fg ects 
 Fractional permissions 
 … Yes Great! ? ”Can your system do this?” Great! No (not yet)

  25. Thank you! Let’s talk more at the poster session! sa Structured Aliasing

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend