• No results found

Kappa: Insights, Status and Future Work

N/A
N/A
Protected

Academic year: 2022

Share "Kappa: Insights, Status and Future Work"

Copied!
25
0
0

Loading.... (view fulltext now)

Full text

(1)

Kappa: Insights, Status and Future Work

Elias Castegren, Tobias Wrigstad IWACO’16

sa

Structured Aliasing

(2)

Elias Castegren, Tobias Wrigstad IWACO’16

sa

Structured Aliasing

Kappa: Insights, Status

and Future Work

(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?

(4)

Aliasing and Concurrency Control

assert c1.value() == 42;

c1.inc();

assert c1.value() == 43;

May alias? c2.inc();

(5)

Aliasing and Concurrency Control

assert c1.value() == 42;

c1.inc();

assert c1.value() == 43;

May alias? c2.inc();

T

1

T

2

Wasteful if unaliased!

Properly synchronised?

Lock EVERYONE!

Locking too much leads to other pr oblems

(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 object

x : linear T

(7)

Modes of Concurrency Control

Exclusive modes

Safe modes

linear thread

read

Globally unique Thread-local

Precludes mutating aliases

locked

Implicit locking

!

(8)

Modes of Concurrency Control

Dominating modes linear

thread

read

Precludes mutating aliases

locked

Subordinate mode

subordinate Guarantees

mutual exclusion

Encapsulated

(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++

linear Inc — Globally unique increment capability

locked Inc — Implicitly synchronised increment capability read Inc — A read-only increment capability

trait Get

require val cnt : int def value() : int

return this.cnt;

read Get — A read-only capability for getting the value

(10)

Classes are Composed by Capabilities

class Counter = Inc ⊕ Get { var cnt : int

}

linear thread

locked read

subordinate

(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();

T

1 May not alias!

T

2

Properly synchronised!

Implemented by a readers-writer lock

(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

(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

(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

(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

(16)

Kappa: Insights, Status and Future Work

Elias Castegren, Tobias Wrigstad IWACO’16

sa

Structured Aliasing

(17)

Subordination and Trait-Based Reuse

Reuse traits across different 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 declar

ations only

No effect tracking or ownership types this : subord Add<T>subord

Can assume exclusive access

(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 effects Ownership

External uniqueness

A⊗B

A

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 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

(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

(22)

Array Capabilities

A⊗B

A B

[A]

[A] [A]

[A⊗B]

[A]

[B]

(23)

Capability

Shared

Atomic Immutable

Unsafe

Lock-Free Active

Subordinate

Optimistic Pessimistic Oblivious

Thread

Locked Read

Exclusive Linear

A Hierarchy of Capabilities

Safe

(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 effects
 Fractional permissions


”Can your system do this?” ?

Great!

Great!

Yes

No (not yet)

(25)

horisont uppsala

2009

Uppsala universitets årsmagasin

Spädbarns sociala kompetens Fler farmaceuter

i vården Innovationer inom

life science

Professorn som skapar blixtar

Thank you!

sa

Structured Aliasing

Let’s talk more at the poster session!

References

Related documents

Tillväxtanalys har haft i uppdrag av rege- ringen att under år 2013 göra en fortsatt och fördjupad analys av följande index: Ekono- miskt frihetsindex (EFW), som

Generella styrmedel kan ha varit mindre verksamma än man har trott De generella styrmedlen, till skillnad från de specifika styrmedlen, har kommit att användas i större

Närmare 90 procent av de statliga medlen (intäkter och utgifter) för näringslivets klimatomställning går till generella styrmedel, det vill säga styrmedel som påverkar

• Utbildningsnivåerna i Sveriges FA-regioner varierar kraftigt. I Stockholm har 46 procent av de sysselsatta eftergymnasial utbildning, medan samma andel i Dorotea endast

På många små orter i gles- och landsbygder, där varken några nya apotek eller försälj- ningsställen för receptfria läkemedel har tillkommit, är nätet av

Industrial Emissions Directive, supplemented by horizontal legislation (e.g., Framework Directives on Waste and Water, Emissions Trading System, etc) and guidance on operating

In this article, we explore the identity work done by four male, working-class students who participate in a Swedish mechanical engineering program, with a focus on their

(Although linear capabilities might be transferred between threads, at any point in time at most one thread can access it.) The locked and read modes are safe modes as they are