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
Kappa: Insights, Status and Future Work Elias Castegren , Tobias Wrigstad IWACO’16 sa Structured Aliasing
Kappa: Insights, Status and Future Work Elias Castegren , Tobias Wrigstad IWACO’16 sa Structured Aliasing
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?
Aliasing and Concurrency Control assert c1.value() == 42; c1.inc(); May alias? c2.inc(); assert c1.value() == 43;
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!
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
Modes of Concurrency Control • Exclusive modes linear Globally unique thread Thread-local • Safe modes ! read locked Precludes mutating Implicit locking aliases
⎭ Modes of Concurrency Control Dominating modes ⎫ linear Guarantees ⎬ thread mutual exclusion locked Subordinate mode read subordinate Precludes mutating Encapsulated aliases
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
Classes are Composed by C apabilities linear thread locked read subordinate class Counter = Inc ⊕ Get { var cnt : int }
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
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
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
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
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
Kappa: Insights, Status and Future Work Elias Castegren , Tobias Wrigstad IWACO’16 sa Structured Aliasing
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>
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
Kappa: Insights, Status and Future Work Elias Castegren , Tobias Wrigstad IWACO’16 sa Structured Aliasing
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
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
Array Capabilities [A] A ⊗ B [A] [A] A B [A] [A ⊗ B] [B]
A Hierarchy of Capabilities Capability Subordinate Exclusive Linear Thread Shared Safe Unsafe Pessimistic … Optimistic Oblivious Atomic Lock-Free Locked Active Read Immutable
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)
Thank you! Let’s talk more at the poster session! sa Structured Aliasing
Recommend
More recommend
Explore More Topics
Stay informed with curated content and fresh updates.