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

kappa insights status and future work
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

Kappa: Insights, Status and Future Work

Elias Castegren, Tobias Wrigstad IWACO’16

sa Structured Aliasing
slide-2
SLIDE 2

Elias Castegren, Tobias Wrigstad IWACO’16

sa Structured Aliasing

Kappa: Insights, Status and Future Work

slide-3
SLIDE 3

Concurrency Imposes Many Concerns

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

slide-4
SLIDE 4

Aliasing and Concurrency Control

assert c1.value() == 42; c1.inc(); assert c1.value() == 43; May alias? c2.inc();

slide-5
SLIDE 5

Aliasing and Concurrency Control

assert c1.value() == 42; c1.inc(); assert c1.value() == 43; May alias? c2.inc();

T1 T2

Wasteful if unaliased! Properly synchronised?

Lock EVERYONE!

Locking too much leads to other problems

slide-6
SLIDE 6

Reference Capabilities

  • A capability grants access to some resource
  • 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

reference

  • bject

x : T linear

slide-7
SLIDE 7

Modes of Concurrency Control

  • Exclusive modes
  • Safe modes

linear thread read Globally unique Thread-local Precludes mutating aliases locked Implicit locking

!

slide-8
SLIDE 8

Modes of Concurrency Control

Dominating modes linear thread read Precludes mutating aliases locked Subordinate mode subordinate Guarantees mutual exclusion Encapsulated

⎫ ⎬ ⎭

slide-9
SLIDE 9

Capability = Trait + Mode

  • Capabilities are introduced via traits
  • Modes control why they are safe

trait Inc require var cnt : int def inc() : void this.cnt++ Inc linear — Globally unique increment capability Inc locked — Implicitly synchronised increment capability Inc read — A read-only increment capability trait Get require val cnt : int def value() : int return this.cnt; Get read — A read-only capability for getting the value

slide-10
SLIDE 10

Classes are Composed by Capabilities

class Counter = Inc ⊕ Get { var cnt : int } linear thread locked read

subordinate

slide-11
SLIDE 11

Aliasing and Concurrency Control (revisited)

Inc ⊕ thread class LocalCounter = read Get Inc ⊕ locked class SharedCounter = read Get assert c1.value() == 42; c1.inc(); assert c1.value() == 43; c2.inc();

T1 T2

May not alias! Properly synchronised! Implemented by a readers-writer lock

slide-12
SLIDE 12
  • 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…
  • A capability conjunction A ⊗ B can be used as A and B, possibly in parallel

trait Fst { require var fst : int … } trait Snd { require var snd : int … }

Composite Capabilities

trait Fst { require var fst : int … } trait Snd { require var snd : int … } class Pair = Fst ⊗ Snd { var fst : int var snd : int } linear linear

slide-13
SLIDE 13

Packing and Unpacking

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

slide-14
SLIDE 14

Packing and Unpacking

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

slide-15
SLIDE 15

Packing and Unpacking

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

slide-16
SLIDE 16

Kappa: Insights, Status and Future Work

Elias Castegren, Tobias Wrigstad IWACO’16

sa Structured Aliasing
slide-17
SLIDE 17

Subordination and Trait-Based Reuse

  • Reuse traits across difgerent concurrency scenarios
  • Separate business logic from concurrency concerns

trait Add<T> require var first : Link<T> def add(elem : T) : void … class List<T> = Add<T> ⊕ … var first : Link<T> thread class SynchronizedList<T> = Add<T> ⊕ … var first : Link<T> locked Annotations in type declarations only No efgect tracking

  • r ownership types

this : subord Add<T> subord Can assume exclusive access

slide-18
SLIDE 18

Reference Capabilities as Primitives

Left Right Elem left right elem class Tree = Left ⊗ Right ⊗ Elem var left : Tree var right : Tree var elem : int

Inc ⊕ linear read Get Inc ⊕ linear

read

Get read Inc ⊕ linear read Get

… multiple disjoint writers Single writer, multiple readers Regions and efgects Ownership External uniqueness

A⊗B A B

slide-19
SLIDE 19

Kappa: Insights, Status and Future Work

Elias Castegren, Tobias Wrigstad IWACO’16

sa Structured Aliasing
slide-20
SLIDE 20

Active Objects as a Mode of Synchronisation

  • The message queue of an active object can replace the synchronisation of locks

class ActiveCounter var cnt : int def inc() : void this.cnt++ def get() : int return this.cnt class ActiveCounter = active Inc ⊕ active Get var cnt : int

active active

Active by default

slide-21
SLIDE 21
  • Opens up for new combinations

Active Objects as a Mode of Synchronisation

active active active active linear locked subord active

⊕ ⊕ ⊕ ⊗

Actor with unsynchronised initialisation methods Actor with priority channel Actor nested in another actor Actor with parallel message queues

slide-22
SLIDE 22

Array Capabilities

A⊗B A B [A] [A] [A] [A⊗B] [A] [B]

slide-23
SLIDE 23

Capability Shared Atomic Immutable Unsafe Lock-Free Active Subordinate Optimistic Pessimistic Oblivious Thread Locked Read Exclusive Linear …

A Hierarchy of Capabilities

Safe

slide-24
SLIDE 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 efgects
 Fractional permissions
 … ? ”Can your system do this?” Great! Great! Yes No(not yet)

slide-25
SLIDE 25

Thank you!

sa Structured Aliasing

Let’s talk more at the poster session!