shared session types for safe, practical concurrencybalzers/publications/safe_concurrency.pdf ·...

296
Shared Session Types for Safe, Practical Concurrency 1 Stephanie Balzer Carnegie Mellon University Typelevel Summit Philadelphia 2019 1 Supported by a Mozilla Research Grant and NSF Grant No. CCF-1718267

Upload: others

Post on 18-Aug-2020

9 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Shared Session Types for Safe, Practical Concurrency1

Stephanie Balzer Carnegie Mellon University

Typelevel Summit Philadelphia 2019

1 Supported by a Mozilla Research Grant and NSF Grant No. CCF-1718267

Page 2: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Concurrency is ubiquitous

�2

Page 3: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Concurrency is ubiquitous

The world surrounding us is inherently concurrent

�2

Page 4: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Concurrency is ubiquitous

The world surrounding us is inherently concurrent

�2

Page 5: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Concurrency is ubiquitous

The world surrounding us is inherently concurrent

�2

Page 6: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Concurrency is ubiquitous

The world surrounding us is inherently concurrent

�2

Page 7: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Concurrency is ubiquitous

The world surrounding us is inherently concurrent

�2

Page 8: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Concurrency is ubiquitous

The world surrounding us is inherently concurrent

�2

Page 9: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Concurrency is ubiquitous

�3

The world surrounding us is inherently concurrent

Page 10: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Concurrency is ubiquitous

Many programming problems demand concurrency • Flight booking system, online store, search engines, etc.

�3

The world surrounding us is inherently concurrent

Page 11: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Concurrency is ubiquitous

Many programming problems demand concurrency • Flight booking system, online store, search engines, etc.

Computing devices themselves are concurrent • Run various apps concurrently

�3

The world surrounding us is inherently concurrent

Page 12: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Concurrency is ubiquitous

Many programming problems demand concurrency • Flight booking system, online store, search engines, etc.

Computing devices themselves are concurrent • Run various apps concurrently

�3

programming languages must support concurrency

The world surrounding us is inherently concurrent

Page 13: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Concurrency is ubiquitous

Many programming problems demand concurrency • Flight booking system, online store, search engines, etc.

Computing devices themselves are concurrent • Run various apps concurrently

�3

programming languages must support concurrency

concurrent programming is notoriously difficult and error-prone

The world surrounding us is inherently concurrent

Page 14: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Two models for concurrent programming

�4

Page 15: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Two models for concurrent programming

�4

Legend: concurrently executing component

shared dataread/write

Shared memory

Page 16: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Two models for concurrent programming

�4

Legend: concurrently executing component

shared dataread/write

Shared memory

message

Message-passing

Page 17: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Two models for concurrent programming

�4

Legend: concurrently executing component

shared dataread/write

Shared memory

message

Message-passing

• computation by reading fromand writing to shared data

Page 18: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Two models for concurrent programming

�4

Legend: concurrently executing component

shared dataread/write

Shared memory

message

Message-passing

• computation by reading fromand writing to shared data

• computation by exchangeof messages

Page 19: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Two models for concurrent programming

�4

Legend: concurrently executing component

shared dataread/write

Shared memory

message

Message-passing

• computation by reading fromand writing to shared data

• computation by exchangeof messages

message-passing offers higher-level of abstraction

Page 20: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Two models for concurrent programming

�4

Legend: concurrently executing component

shared dataread/write

Shared memory

message

Message-passing

• computation by reading fromand writing to shared data

• computation by exchangeof messages

message-passing offers higher-level of abstraction

message-passing adopted by practical languages such as Erlang, Go, and Rust.

Page 21: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

My research

�5

Page 22: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

My research

�5

Goal: make concurrent programming safe and practical

Page 23: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

My research

�5

Goal: make concurrent programming safe and practical

message-passing model

session types to express protocols of message exchange and reason sequentially about communicating parties

Page 24: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

My research

�5

Goal: make concurrent programming safe and practical

message-passing model

Contributions:

session types to express protocols of message exchange and reason sequentially about communicating parties

Page 25: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

My research

�5

Goal: make concurrent programming safe and practical

message-passing model

Contributions:shared session types

session types to express protocols of message exchange and reason sequentially about communicating parties

Page 26: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

My research

�5

Goal: make concurrent programming safe and practical

message-passing model

Contributions:shared session types

accommodate real-world programming scenarios

guarantee protocol adherence, data-race-freedom, and deadlock-freedom

session types to express protocols of message exchange and reason sequentially about communicating parties

Page 27: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Session types, what are they? Why do we need them in practice?

�6

Page 28: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Message-passing concurrency in Servo

�7

Page 29: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Message-passing concurrency in Servo

• Servo is Mozilla’s next-generation browser engine under development and implemented in Rust.

• Servo uses message-passing concurrency for maximal parallelization of tasks, such as loading and rendering of webpage elements.

�7

Page 30: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Message-passing concurrency in Servo

• Servo is Mozilla’s next-generation browser engine under development and implemented in Rust.

• Servo uses message-passing concurrency for maximal parallelization of tasks, such as loading and rendering of webpage elements.

�7

Image loader:

Page 31: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Message-passing concurrency in Servo

• Servo is Mozilla’s next-generation browser engine under development and implemented in Rust.

• Servo uses message-passing concurrency for maximal parallelization of tasks, such as loading and rendering of webpage elements.

�7

ImageCache

Image loader:

Page 32: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Message-passing concurrency in Servo

• Servo is Mozilla’s next-generation browser engine under development and implemented in Rust.

• Servo uses message-passing concurrency for maximal parallelization of tasks, such as loading and rendering of webpage elements.

�7

ImageCache Client

CmdReceiver

Legend: channelcomponent, runs in separate thread

Image loader:

Page 33: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Message-passing concurrency in Servo

• Servo is Mozilla’s next-generation browser engine under development and implemented in Rust.

• Servo uses message-passing concurrency for maximal parallelization of tasks, such as loading and rendering of webpage elements.

�7

ResourceThread ImageCache Client

CmdReceiver

Legend: channelcomponent, runs in separate thread

Image loader:

Page 34: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Message-passing concurrency in Servo

• Servo is Mozilla’s next-generation browser engine under development and implemented in Rust.

• Servo uses message-passing concurrency for maximal parallelization of tasks, such as loading and rendering of webpage elements.

�7

ResourceThread ImageCache Client

CmdReceiver

Decoder1 Decodern

Legend: channelcomponent, runs in separate thread

Image loader:

Page 35: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Message-passing concurrency in Servo

• Servo is Mozilla’s next-generation browser engine under development and implemented in Rust.

• Servo uses message-passing concurrency for maximal parallelization of tasks, such as loading and rendering of webpage elements.

�7

ResourceThread ImageCache Client

CmdReceiver

Decoder1 Decodern

Legend: channelcomponent, runs in separate thread

request

Image loader:

Page 36: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Message-passing concurrency in Servo

• Servo is Mozilla’s next-generation browser engine under development and implemented in Rust.

• Servo uses message-passing concurrency for maximal parallelization of tasks, such as loading and rendering of webpage elements.

�8

ResourceThread ImageCache Client

CmdReceiver

Decoder1 Decodern

Legend: channelcomponent, runs in separate thread

Image loader:

Page 37: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Message-passing concurrency in Servo

• Servo is Mozilla’s next-generation browser engine under development and implemented in Rust.

• Servo uses message-passing concurrency for maximal parallelization of tasks, such as loading and rendering of webpage elements.

�8

ResourceThread ImageCache Client

CmdReceiver

Decoder1 Decodern

Legend: channelcomponent, runs in separate thread

exit

Image loader:

Page 38: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Message-passing concurrency in Servo

• Servo is Mozilla’s next-generation browser engine under development and implemented in Rust.

• Servo uses message-passing concurrency for maximal parallelization of tasks, such as loading and rendering of webpage elements.

�9

ResourceThread ImageCache Client

CmdReceiver

Decoder1 Decodern

Legend: channelcomponent, runs in separate thread

Image loader:

Page 39: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Message-passing concurrency in Servo

• Servo is Mozilla’s next-generation browser engine under development and implemented in Rust.

• Servo uses message-passing concurrency for maximal parallelization of tasks, such as loading and rendering of webpage elements.

�9

ResourceThread ImageCache Client

CmdReceiver

Decoder1 Decodern

Legend: channelcomponent, runs in separate thread

kill

Image loader:

Page 40: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Message-passing concurrency in Servo

�10

ResourceThread ImageCache Client

CmdReceiver

Decoder1 Decodern

Legend: channelcomponent, runs in separate thread

Image loader:

Page 41: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Message-passing concurrency in Servo

�10

ResourceThread ImageCache Client

CmdReceiver

Decoder1 Decodern

Legend: channelcomponent, runs in separate thread

To restrict the kinds of messages that can be sent over a channel, Rust channels are typed with enumeration types.

Image loader:

Page 42: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Message-passing concurrency in Servo

�10

ResourceThread ImageCache Client

CmdReceiver

Decoder1 Decodern

Legend: channelcomponent, runs in separate thread

To restrict the kinds of messages that can be sent over a channel, Rust channels are typed with enumeration types.

Image loader:

Example: enumeration for ImageCache

Page 43: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Message-passing concurrency in Servo

�11

ResourceThread ImageCache Client

CmdReceiver

Decoder1 Decodern

Legend: channelcomponent, runs in separate thread

Image loader:

Page 44: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Message-passing concurrency in Servo

�11

ResourceThread ImageCache Client

CmdReceiver

Decoder1 Decodern

Legend: channelcomponent, runs in separate thread

pub enum ImageCacheCommand { RequestImage (Url, ImageCacheChan, Option<ImageResponder>), GetImageIfAvailable (Url, UsePlaceholder, IpcSender<Result<Arc<Image>, ImageState>>), StoreDecodeImage (Url, Vec<u8>), … // Clients must wait for a response before shutting down ResourceThread Exit () }

Image loader:

Page 45: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Message-passing concurrency in Servo

�11

ResourceThread ImageCache Client

CmdReceiver

Decoder1 Decodern

Legend: channelcomponent, runs in separate thread

pub enum ImageCacheCommand { RequestImage (Url, ImageCacheChan, Option<ImageResponder>), GetImageIfAvailable (Url, UsePlaceholder, IpcSender<Result<Arc<Image>, ImageState>>), StoreDecodeImage (Url, Vec<u8>), … // Clients must wait for a response before shutting down ResourceThread Exit () }

Image loader:

Page 46: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Message-passing concurrency in Servo

�11

ResourceThread ImageCache Client

CmdReceiver

Decoder1 Decodern

Legend: channelcomponent, runs in separate thread

pub enum ImageCacheCommand { RequestImage (Url, ImageCacheChan, Option<ImageResponder>), GetImageIfAvailable (Url, UsePlaceholder, IpcSender<Result<Arc<Image>, ImageState>>), StoreDecodeImage (Url, Vec<u8>), … // Clients must wait for a response before shutting down ResourceThread Exit () }

one variant for each message

Image loader:

Page 47: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Message-passing concurrency in Servo

�12

ResourceThread ImageCache Client

CmdReceiver

Decoder1 Decodern

Legend: channelcomponent, runs in separate thread

pub enum ImageCacheCommand { RequestImage (Url, ImageCacheChan, Option<ImageResponder>), GetImageIfAvailable (Url, UsePlaceholder, IpcSender<Result<Arc<Image>, ImageState>>), StoreDecodeImage (Url, Vec<u8>), … // Clients must wait for a response before shutting down ResourceThread Exit () }

Image loader:

Page 48: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Message-passing concurrency in Servo

�12

ResourceThread ImageCache Client

CmdReceiver

Decoder1 Decodern

Legend: channelcomponent, runs in separate thread

pub enum ImageCacheCommand { RequestImage (Url, ImageCacheChan, Option<ImageResponder>), GetImageIfAvailable (Url, UsePlaceholder, IpcSender<Result<Arc<Image>, ImageState>>), StoreDecodeImage (Url, Vec<u8>), … // Clients must wait for a response before shutting down ResourceThread Exit () }

Image loader:

Page 49: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Message-passing concurrency in Servo

�12

ResourceThread ImageCache Client

CmdReceiver

Decoder1 Decodern

Legend: channelcomponent, runs in separate thread

pub enum ImageCacheCommand { RequestImage (Url, ImageCacheChan, Option<ImageResponder>), GetImageIfAvailable (Url, UsePlaceholder, IpcSender<Result<Arc<Image>, ImageState>>), StoreDecodeImage (Url, Vec<u8>), … // Clients must wait for a response before shutting down ResourceThread Exit () }

implicit protocolImage loader:

Page 50: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Message-passing concurrency in Servo

�12

ResourceThread ImageCache Client

CmdReceiver

Decoder1 Decodern

Legend: channelcomponent, runs in separate thread

pub enum ImageCacheCommand { RequestImage (Url, ImageCacheChan, Option<ImageResponder>), GetImageIfAvailable (Url, UsePlaceholder, IpcSender<Result<Arc<Image>, ImageState>>), StoreDecodeImage (Url, Vec<u8>), … // Clients must wait for a response before shutting down ResourceThread Exit () }

implicit protocolImage loader:

protocol breaches result in proliferation of panic! and

infinite waiting

Page 51: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Message-passing concurrency in Servo

�13

pub enum ImageCacheCommand { RequestImage (Url, ImageCacheChan, Option<ImageResponder>), GetImageIfAvailable (Url, UsePlaceholder, IpcSender<Result<Arc<Image>, ImageState>>), StoreDecodeImage (Url, Vec<u8>), … // Clients must wait for a response before shutting down ResourceThread Exit () }

implicit protocol

protocol breaches result in proliferation of panic! and

infinite waiting

Page 52: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Message-passing concurrency in Servo

�13

pub enum ImageCacheCommand { RequestImage (Url, ImageCacheChan, Option<ImageResponder>), GetImageIfAvailable (Url, UsePlaceholder, IpcSender<Result<Arc<Image>, ImageState>>), StoreDecodeImage (Url, Vec<u8>), … // Clients must wait for a response before shutting down ResourceThread Exit () }

implicit protocol

enumeration types ensure that only defined messages can be communicated along a channel

protocol breaches result in proliferation of panic! and

infinite waiting

Page 53: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Message-passing concurrency in Servo

�13

pub enum ImageCacheCommand { RequestImage (Url, ImageCacheChan, Option<ImageResponder>), GetImageIfAvailable (Url, UsePlaceholder, IpcSender<Result<Arc<Image>, ImageState>>), StoreDecodeImage (Url, Vec<u8>), … // Clients must wait for a response before shutting down ResourceThread Exit () }

implicit protocol

enumeration types ensure that only defined messages can be communicated along a channel

enumeration types fail to ensure that messages are sent according to the intended protocol

protocol breaches result in proliferation of panic! and

infinite waiting

Page 54: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Message-passing concurrency in Servo

�13

pub enum ImageCacheCommand { RequestImage (Url, ImageCacheChan, Option<ImageResponder>), GetImageIfAvailable (Url, UsePlaceholder, IpcSender<Result<Arc<Image>, ImageState>>), StoreDecodeImage (Url, Vec<u8>), … // Clients must wait for a response before shutting down ResourceThread Exit () }

implicit protocol

enumeration types ensure that only defined messages can be communicated along a channel

enumeration types fail to ensure that messages are sent according to the intended protocol

let’s use session types!

protocol breaches result in proliferation of panic! and

infinite waiting

Page 55: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Session types

�14

Page 56: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Session types

�14

Session types define protocols of message exchange.

Page 57: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Session types

�14

Session types define protocols of message exchange.

“protocol = sequence of actions”

Page 58: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Session types

�14

Session types define protocols of message exchange.

“protocol = sequence of actions”

A,B , N{li : Ai} external choice

�{li : Ai} internal choice

A ( B channel input

A⌦B channel output

1 termination

T ! A value input

T ⇥A value output

T , int | string | . . .

Page 59: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Session types

�14

Session types define protocols of message exchange.

“protocol = sequence of actions”

A,B , N{li : Ai} external choice

�{li : Ai} internal choice

A ( B channel input

A⌦B channel output

1 termination

T ! A value input

T ⇥A value output

T , int | string | . . .

client chooses among sending

one of the labels li

Page 60: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Session types

�15

Session types define protocols of message exchange.

“protocol = sequence of actions”

A,B , N{li : Ai} external choice

�{li : Ai} internal choice

A ( B channel input

A⌦B channel output

1 termination

T ! A value input

T ⇥A value output

T , int | string | . . .

Page 61: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Session types

�15

Session types define protocols of message exchange.

“protocol = sequence of actions”

A,B , N{li : Ai} external choice

�{li : Ai} internal choice

A ( B channel input

A⌦B channel output

1 termination

T ! A value input

T ⇥A value output

T , int | string | . . .

provider chooses among sending

one of the labels li

Page 62: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Session types

�16

Session types define protocols of message exchange.

“protocol = sequence of actions”

A,B , N{li : Ai} external choice

�{li : Ai} internal choice

A ( B channel input

A⌦B channel output

1 termination

T ! A value input

T ⇥A value output

T , int | string | . . .

Page 63: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Session types

�16

Session types define protocols of message exchange.

“protocol = sequence of actions”

A,B , N{li : Ai} external choice

�{li : Ai} internal choice

A ( B channel input

A⌦B channel output

1 termination

T ! A value input

T ⇥A value output

T , int | string | . . .

client sends channel reference of

type A

Page 64: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Session types

�17

Session types define protocols of message exchange.

“protocol = sequence of actions”

A,B , N{li : Ai} external choice

�{li : Ai} internal choice

A ( B channel input

A⌦B channel output

1 termination

T ! A value input

T ⇥A value output

T , int | string | . . .

Page 65: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Session types

�17

Session types define protocols of message exchange.

“protocol = sequence of actions”

A,B , N{li : Ai} external choice

�{li : Ai} internal choice

A ( B channel input

A⌦B channel output

1 termination

T ! A value input

T ⇥A value output

T , int | string | . . .

provider sends channel reference of

type A

Page 66: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Session types

�18

Session types define protocols of message exchange.

“protocol = sequence of actions”

A,B , N{li : Ai} external choice

�{li : Ai} internal choice

A ( B channel input

A⌦B channel output

1 termination

T ! A value input

T ⇥A value output

T , int | string | . . .

Page 67: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Session types

�18

Session types define protocols of message exchange.

“protocol = sequence of actions”

A,B , N{li : Ai} external choice

�{li : Ai} internal choice

A ( B channel input

A⌦B channel output

1 termination

T ! A value input

T ⇥A value output

T , int | string | . . .provider terminates

Page 68: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Session types

�18

Session types define protocols of message exchange.

“protocol = sequence of actions”

A,B , N{li : Ai} external choice

�{li : Ai} internal choice

A ( B channel input

A⌦B channel output

1 termination

T ! A value input

T ⇥A value output

T , int | string | . . .

Page 69: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Session types

�19

Session types define protocols of message exchange.

“protocol = sequence of actions”

A,B , N{li : Ai} external choice

�{li : Ai} internal choice

A ( B channel input

A⌦B channel output

1 termination

T ! A value input

T ⇥A value output

T , int | string | . . .

Page 70: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Session types

�19

Session types define protocols of message exchange.

“protocol = sequence of actions”

A,B , N{li : Ai} external choice

�{li : Ai} internal choice

A ( B channel input

A⌦B channel output

1 termination

T ! A value input

T ⇥A value output

T , int | string | . . .

support communication of

values

Page 71: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Session type for image loader

�20

A,B , N{li : Ai} external choice

�{li : Ai} internal choice

A ( B channel input

A⌦B channel output

1 termination

T ! A value input

T ⇥A value output

T , int | string | . . .

Page 72: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Session type for image loader

�20

A,B , N{li : Ai} external choice

�{li : Ai} internal choice

A ( B channel input

A⌦B channel output

1 termination

T ! A value input

T ⇥A value output

T , int | string | . . .

ImgCacheCmd = N {RequestImage : string ! Requester ( ImgCacheCmd,. . .Exit : � {Running : ImgCacheCmd,

Done : ResourceThread⌦ 1}}

Page 73: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Session type for image loader

�21

A,B , N{li : Ai} external choice

�{li : Ai} internal choice

A ( B channel input

A⌦B channel output

1 termination

T ! A value input

T ⇥A value output

T , int | string | . . .

ImgCacheCmd = N {RequestImage : string ! Requester ( ImgCacheCmd,. . .Exit : � {Running : ImgCacheCmd,

Done : ResourceThread⌦ 1}}

Page 74: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Session type for image loader

�22

A,B , N{li : Ai} external choice

�{li : Ai} internal choice

A ( B channel input

A⌦B channel output

1 termination

T ! A value input

T ⇥A value output

T , int | string | . . .

ImgCacheCmd = N {RequestImage : string ! Requester ( ImgCacheCmd,. . .Exit : � {Running : ImgCacheCmd,

Done : ResourceThread⌦ 1}}

Page 75: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Session type for image loader

�23

A,B , N{li : Ai} external choice

�{li : Ai} internal choice

A ( B channel input

A⌦B channel output

1 termination

T ! A value input

T ⇥A value output

T , int | string | . . .

ImgCacheCmd = N {RequestImage : string ! Requester ( ImgCacheCmd,. . .Exit : � {Running : ImgCacheCmd,

Done : ResourceThread⌦ 1}}

Page 76: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Session type for image loader

�24

A,B , N{li : Ai} external choice

�{li : Ai} internal choice

A ( B channel input

A⌦B channel output

1 termination

T ! A value input

T ⇥A value output

T , int | string | . . .

ImgCacheCmd = N {RequestImage : string ! Requester ( ImgCacheCmd,. . .Exit : � {Running : ImgCacheCmd,

Done : ResourceThread⌦ 1}}

Page 77: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Session type for image loader

�25

ImgCacheCmd = N {RequestImage : string ! Requester ( ImgCacheCmd,. . .Exit : � {Running : ImgCacheCmd,

Done : ResourceThread⌦ 1}}

Page 78: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Session type for image loader

�25

ImgCacheCmd = N {RequestImage : string ! Requester ( ImgCacheCmd,. . .Exit : � {Running : ImgCacheCmd,

Done : ResourceThread⌦ 1}}

ResourceThread ImageCache Client

CmdReceiver

Decoder1 Decodern

Page 79: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Session type for image loader

�25

ImgCacheCmd = N {RequestImage : string ! Requester ( ImgCacheCmd,. . .Exit : � {Running : ImgCacheCmd,

Done : ResourceThread⌦ 1}}

ImageCache:

ResourceThread ImageCache Client

CmdReceiver

Decoder1 Decodern

Page 80: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Session type for image loader

�25

ImgCacheCmd = N {RequestImage : string ! Requester ( ImgCacheCmd,. . .Exit : � {Running : ImgCacheCmd,

Done : ResourceThread⌦ 1}}

ImageCache:

ResourceThread ImageCache Client

CmdReceiver

Decoder1 Decodern

ImgCacheCmd

Page 81: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Session type for image loader

�25

ImgCacheCmd = N {RequestImage : string ! Requester ( ImgCacheCmd,. . .Exit : � {Running : ImgCacheCmd,

Done : ResourceThread⌦ 1}}

ImageCache:

ResourceThread ImageCache Client

CmdReceiver

Decoder1 Decodern

RequestImage

ImgCacheCmd

Page 82: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Session type for image loader

�26

ImgCacheCmd = N {RequestImage : string ! Requester ( ImgCacheCmd,. . .Exit : � {Running : ImgCacheCmd,

Done : ResourceThread⌦ 1}}

ImageCache:

ResourceThread ImageCache Client

CmdReceiver

Decoder1 Decodern

Page 83: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Session type for image loader

�26

ImgCacheCmd = N {RequestImage : string ! Requester ( ImgCacheCmd,. . .Exit : � {Running : ImgCacheCmd,

Done : ResourceThread⌦ 1}}

ImageCache:

ResourceThread ImageCache Client

CmdReceiver

Decoder1 Decodern

string ! Requester ( ImgCacheCmd

Page 84: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Session type for image loader

�26

ImgCacheCmd = N {RequestImage : string ! Requester ( ImgCacheCmd,. . .Exit : � {Running : ImgCacheCmd,

Done : ResourceThread⌦ 1}}

ImageCache:

ResourceThread ImageCache Client

CmdReceiver

Decoder1 Decodern

“http://…”

string ! Requester ( ImgCacheCmd

Page 85: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Session type for image loader

�27

ImgCacheCmd = N {RequestImage : string ! Requester ( ImgCacheCmd,. . .Exit : � {Running : ImgCacheCmd,

Done : ResourceThread⌦ 1}}

ImageCache:

ResourceThread ImageCache Client

CmdReceiver

Decoder1 Decodern

Requester ( ImgCacheCmd

Page 86: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Session type for image loader

�27

ImgCacheCmd = N {RequestImage : string ! Requester ( ImgCacheCmd,. . .Exit : � {Running : ImgCacheCmd,

Done : ResourceThread⌦ 1}}

ImageCache:

ResourceThread ImageCache Client

CmdReceiver

Decoder1 Decodern

c

Requester ( ImgCacheCmd

Page 87: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Session type for image loader

�28

ImgCacheCmd = N {RequestImage : string ! Requester ( ImgCacheCmd,. . .Exit : � {Running : ImgCacheCmd,

Done : ResourceThread⌦ 1}}

ImageCache:

ResourceThread ImageCache Client

CmdReceiver

Decoder1 Decodern

ImgCacheCmd

Page 88: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Session type for image loader

�28

ImgCacheCmd = N {RequestImage : string ! Requester ( ImgCacheCmd,. . .Exit : � {Running : ImgCacheCmd,

Done : ResourceThread⌦ 1}}

ImageCache:

ResourceThread ImageCache Client

CmdReceiver

Decoder1 Decodern

Exit

ImgCacheCmd

Page 89: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Session type for image loader

�29

ImgCacheCmd = N {RequestImage : string ! Requester ( ImgCacheCmd,. . .Exit : � {Running : ImgCacheCmd,

Done : ResourceThread⌦ 1}}

ImageCache:

ResourceThread ImageCache Client

CmdReceiver

Decoder1 Decodern

�{Running : ImgCacheCmd,Done : ResourceThread⌦ 1}

Page 90: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Session type for image loader

�29

ImgCacheCmd = N {RequestImage : string ! Requester ( ImgCacheCmd,. . .Exit : � {Running : ImgCacheCmd,

Done : ResourceThread⌦ 1}}

ImageCache:

ResourceThread ImageCache Client

CmdReceiver

Decoder1 Decodern

Running

�{Running : ImgCacheCmd,Done : ResourceThread⌦ 1}

Page 91: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Session type for image loader

�30

ImgCacheCmd = N {RequestImage : string ! Requester ( ImgCacheCmd,. . .Exit : � {Running : ImgCacheCmd,

Done : ResourceThread⌦ 1}}

ImageCache:

ResourceThread ImageCache Client

CmdReceiver

Decoder1 Decodern

ImgCacheCmd

Page 92: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Session type for image loader

�30

ImageCache:

ResourceThread ImageCache Client

CmdReceiver

Decoder1 Decodern

ImgCacheCmd

Page 93: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Session type for image loader

�31

ImageCache:

ResourceThread ImageCache Client

CmdReceiver

Decoder1 Decodern

ImgCacheCmd

components change their session type along with message exchange

Page 94: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Taking stock

�32

Page 95: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Taking stock

• Session types make explicit the protocols of message exchange between concurrently executing components.

�32

Page 96: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Taking stock

• Session types make explicit the protocols of message exchange between concurrently executing components.

• Typing ensures protocol adherence.

�32

Page 97: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Taking stock

• Session types make explicit the protocols of message exchange between concurrently executing components.

• Typing ensures protocol adherence.

• Types make explicit interdependencies between components, enabling sequential reasoning about a component.

�32

Page 98: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Taking stock

• Session types make explicit the protocols of message exchange between concurrently executing components.

• Typing ensures protocol adherence.

• Types make explicit interdependencies between components, enabling sequential reasoning about a component.

�32

Session types are the types of message-passing concurrency.

Page 99: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Session types in research and practice

�33

Page 100: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Session types in research and practice

Research • active research area since inception in 90s [Honda 1993] • logical reconstruction based on linear logic, providing strong

guarantees [Caires & Pfenning 2010, Wadler 2012] • extension of logical session types to sharing [Balzer & Pfenning ICFP

2017, Balzer et al. CONCUR 2018, Balzer et al. ESOP 2019]

�33

Page 101: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Session types in research and practice

Research • active research area since inception in 90s [Honda 1993] • logical reconstruction based on linear logic, providing strong

guarantees [Caires & Pfenning 2010, Wadler 2012] • extension of logical session types to sharing [Balzer & Pfenning ICFP

2017, Balzer et al. CONCUR 2018, Balzer et al. ESOP 2019]

Practice • Lightweight integration of session types or session libraries (with

varying static guarantees) into Scala, Java, Haskell, OCaml, Go, Rust, Python.

• Collaboration with Mozilla Research on integrating our work.

�33

Page 102: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Session types in research and practice

Research • active research area since inception in 90s [Honda 1993] • logical reconstruction based on linear logic, providing strong

guarantees [Caires & Pfenning 2010, Wadler 2012] • extension of logical session types to sharing [Balzer & Pfenning ICFP

2017, Balzer et al. CONCUR 2018, Balzer et al. ESOP 2019]

Practice • Lightweight integration of session types or session libraries (with

varying static guarantees) into Scala, Java, Haskell, OCaml, Go, Rust, Python.

• Collaboration with Mozilla Research on integrating our work.

�33

Page 103: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Logic-based shared session types

�34

Page 104: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Linear logic session types

�35

Page 105: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Linear logic session types

Provide strong guarantees: • Data-race-freedom • Protocol adherence (a.k.a. session fidelity, preservation) • Deadlock-freedom (a.k.a. progress)

�35

Page 106: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Linear logic session types

Provide strong guarantees: • Data-race-freedom • Protocol adherence (a.k.a. session fidelity, preservation) • Deadlock-freedom (a.k.a. progress)

�35

exactly one client

Page 107: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Linear logic session types

Provide strong guarantees: • Data-race-freedom • Protocol adherence (a.k.a. session fidelity, preservation) • Deadlock-freedom (a.k.a. progress)

�35

exactly one client

processes graph forms a tree at run-time

Page 108: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Linear logic session types

Provide strong guarantees • Data-race-freedom • Protocol adherence (a.k.a. session fidelity, preservation) • Deadlock-freedom (a.k.a. progress)

But, they rule out sharing

�36

Page 109: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Linear logic session types

Provide strong guarantees • Data-race-freedom • Protocol adherence (a.k.a. session fidelity, preservation) • Deadlock-freedom (a.k.a. progress)

But, they rule out sharing

�36

ResourceThread ImageCache Client

CmdReceiver

Decoder1 Decodern

Page 110: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Linear logic session types

Provide strong guarantees • Data-race-freedom • Protocol adherence (a.k.a. session fidelity, preservation) • Deadlock-freedom (a.k.a. progress)

But, they rule out sharing

�36

ResourceThread ImageCache Client

CmdReceiver

Decoder1 Decodern

both CmdReceiver and Client communicate with

ImageCache

Page 111: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Linear logic session types

Provide strong guarantees • Data-race-freedom • Protocol adherence (a.k.a. session fidelity, preservation) • Deadlock-freedom (a.k.a. progress)

But, they rule out sharing

�37

Linear logic session types cannot accommodate certain practical programming scenarios.

Page 112: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Linear logic session types

Provide strong guarantees • Data-race-freedom • Protocol adherence (a.k.a. session fidelity, preservation) • Deadlock-freedom (a.k.a. progress)

But, they rule out sharing

�37

Let’s introduce sharing while maintaining above guarantees.

Linear logic session types cannot accommodate certain practical programming scenarios.

Page 113: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Challenges of sharing

�38

Page 114: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Challenges of sharing

�38

ImgCacheCmd = N {RequestImage : string ! Requester ( ImgCacheCmd,. . .Exit : � {Running : ImgCacheCmd,

Done : ResourceThread⌦ 1}}

ResourceThread ImageCache Client

CmdReceiver

Decoder1 Decodern

Page 115: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Challenges of sharing

�38

ImgCacheCmd = N {RequestImage : string ! Requester ( ImgCacheCmd,. . .Exit : � {Running : ImgCacheCmd,

Done : ResourceThread⌦ 1}}

ImageCache:

ResourceThread ImageCache Client

CmdReceiver

Decoder1 Decodern

ImgCacheCmd

Page 116: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Challenges of sharing

�38

ImgCacheCmd = N {RequestImage : string ! Requester ( ImgCacheCmd,. . .Exit : � {Running : ImgCacheCmd,

Done : ResourceThread⌦ 1}}

ImageCache:

ResourceThread ImageCache Client

CmdReceiver

Decoder1 Decodern

RequestImage

ImgCacheCmd

Page 117: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Challenges of sharing

�39

ImgCacheCmd = N {RequestImage : string ! Requester ( ImgCacheCmd,. . .Exit : � {Running : ImgCacheCmd,

Done : ResourceThread⌦ 1}}

ImageCache:

ResourceThread ImageCache Client

CmdReceiver

Decoder1 Decodern

string ! Requester ( ImgCacheCmd

Page 118: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Challenges of sharing

�39

ImgCacheCmd = N {RequestImage : string ! Requester ( ImgCacheCmd,. . .Exit : � {Running : ImgCacheCmd,

Done : ResourceThread⌦ 1}}

ImageCache:

ResourceThread ImageCache Client

CmdReceiver

Decoder1 Decodern

Exit

string ! Requester ( ImgCacheCmd

protocol violated!

Page 119: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Challenges of sharing

�40

ImgCacheCmd = N {RequestImage : string ! Requester ( ImgCacheCmd,. . .Exit : � {Running : ImgCacheCmd,

Done : ResourceThread⌦ 1}}

ResourceThread ImageCache Client

CmdReceiver

Decoder1 Decodern

How to restore protocol adherence in the presence of sharing (a.k.a. aliasing)?

Page 120: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Idea: acquire-release

�41

Page 121: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Idea: acquire-release

�41

Clients of shared channels must communicate along that channel in mutual exclusion from each other.

Page 122: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Idea: acquire-release

�41

Clients of shared channels must communicate along that channel in mutual exclusion from each other.

Acquiring a shared channel gives exclusive access, releasing an acquired channel relinquishes exclusive access.

Page 123: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Idea: acquire-release

�41

Clients of shared channels must communicate along that channel in mutual exclusion from each other.

Acquiring a shared channel gives exclusive access, releasing an acquired channel relinquishes exclusive access.

ResourceThread ImageCache Client

CmdReceiver

Decoder1 Decodern

Page 124: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Idea: acquire-release

�42

Clients of shared channels must communicate along that channel in mutual exclusion from each other.

Acquiring a shared channel gives exclusive access, releasing an acquired channel relinquishes exclusive access.

ResourceThread ImageCache Client

CmdReceiver

Decoder1 Decodern

Legend: shared channel

Page 125: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Idea: acquire-release

�42

Clients of shared channels must communicate along that channel in mutual exclusion from each other.

Acquiring a shared channel gives exclusive access, releasing an acquired channel relinquishes exclusive access.

ResourceThread ImageCache Client

CmdReceiver

Decoder1 Decodern

Legend: shared channel

acquire

Page 126: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Idea: acquire-release

�43

Clients of shared channels must communicate along that channel in mutual exclusion from each other.

Acquiring a shared channel gives exclusive access, releasing an acquired channel relinquishes exclusive access.

ResourceThread ImageCache Client

CmdReceiver

Decoder1 Decodern

Legend: shared channel linear channel

Page 127: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Idea: acquire-release

�43

Clients of shared channels must communicate along that channel in mutual exclusion from each other.

Acquiring a shared channel gives exclusive access, releasing an acquired channel relinquishes exclusive access.

ResourceThread ImageCache Client

CmdReceiver

Decoder1 Decodern

Legend: shared channel linear channel

critical section

Page 128: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Idea: acquire-release

�43

Clients of shared channels must communicate along that channel in mutual exclusion from each other.

Acquiring a shared channel gives exclusive access, releasing an acquired channel relinquishes exclusive access.

ResourceThread ImageCache Client

CmdReceiver

Decoder1 Decodern

release

Legend: shared channel linear channel

critical section

Page 129: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Idea: acquire-release

�44

Clients of shared channels must communicate along that channel in mutual exclusion from each other.

Acquiring a shared channel gives exclusive access, releasing an acquired channel relinquishes exclusive access.

ResourceThread ImageCache Client

CmdReceiver

Decoder1 Decodern

Legend: shared channel linear channel

Page 130: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Have we restored protocol adherence?

�45

Page 131: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Have we restored protocol adherence?

�45

ResourceThread ImageCache Client

CmdReceiver

Decoder1 Decodern

Legend: shared channel linear channel

ImgCacheCmd = N{RequestImage : string ! Requester ( ImgCacheCmd,Exit : � {Running : ImgCacheCmd,

Done : ResourceThread⌦ 1}}

Page 132: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Have we restored protocol adherence?

�45

ResourceThread ImageCache Client

CmdReceiver

Decoder1 Decodern

Legend: shared channel linear channel

ImageCache: ImgCacheCmd

ImgCacheCmd = N{RequestImage : string ! Requester ( ImgCacheCmd,Exit : � {Running : ImgCacheCmd,

Done : ResourceThread⌦ 1}}

Page 133: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Have we restored protocol adherence?

�45

ResourceThread ImageCache Client

CmdReceiver

Decoder1 Decodern

Legend: shared channel linear channel

acquire

ImageCache: ImgCacheCmd

ImgCacheCmd = N{RequestImage : string ! Requester ( ImgCacheCmd,Exit : � {Running : ImgCacheCmd,

Done : ResourceThread⌦ 1}}

Page 134: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Have we restored protocol adherence?

�46

ResourceThread ImageCache Client

CmdReceiver

Decoder1 Decodern

Legend: shared channel linear channel

ImageCache: ImgCacheCmd

ImgCacheCmd = N{RequestImage : string ! Requester ( ImgCacheCmd,Exit : � {Running : ImgCacheCmd,

Done : ResourceThread⌦ 1}}

Page 135: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Have we restored protocol adherence?

�46

ResourceThread ImageCache Client

CmdReceiver

Decoder1 Decodern

Legend: shared channel linear channel

ImageCache: ImgCacheCmd

ImgCacheCmd = N{RequestImage : string ! Requester ( ImgCacheCmd,Exit : � {Running : ImgCacheCmd,

Done : ResourceThread⌦ 1}}

RequestImage

Page 136: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Have we restored protocol adherence?

�47

ResourceThread ImageCache Client

CmdReceiver

Decoder1 Decodern

Legend: shared channel linear channel

ImageCache:

ImgCacheCmd = N{RequestImage : string ! Requester ( ImgCacheCmd,Exit : � {Running : ImgCacheCmd,

Done : ResourceThread⌦ 1}}

string ! Requester ( ImgCacheCmd

Page 137: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Have we restored protocol adherence?

�47

ResourceThread ImageCache Client

CmdReceiver

Decoder1 Decodern

Legend: shared channel linear channel

ImageCache:

ImgCacheCmd = N{RequestImage : string ! Requester ( ImgCacheCmd,Exit : � {Running : ImgCacheCmd,

Done : ResourceThread⌦ 1}}

release

string ! Requester ( ImgCacheCmd

Page 138: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Have we restored protocol adherence?

�48

ResourceThread ImageCache Client

CmdReceiver

Decoder1 Decodern

Legend: shared channel linear channel

ImageCache:

ImgCacheCmd = N{RequestImage : string ! Requester ( ImgCacheCmd,Exit : � {Running : ImgCacheCmd,

Done : ResourceThread⌦ 1}}

string ! Requester ( ImgCacheCmd

Page 139: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Have we restored protocol adherence?

�48

ResourceThread ImageCache Client

CmdReceiver

Decoder1 Decodern

Legend: shared channel linear channel

ImageCache:

ImgCacheCmd = N{RequestImage : string ! Requester ( ImgCacheCmd,Exit : � {Running : ImgCacheCmd,

Done : ResourceThread⌦ 1}}

string ! Requester ( ImgCacheCmd

acquire

Page 140: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Have we restored protocol adherence?

�49

ResourceThread ImageCache Client

CmdReceiver

Decoder1 Decodern

Legend: shared channel linear channel

ImageCache:

ImgCacheCmd = N{RequestImage : string ! Requester ( ImgCacheCmd,Exit : � {Running : ImgCacheCmd,

Done : ResourceThread⌦ 1}}

string ! Requester ( ImgCacheCmd

Page 141: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Have we restored protocol adherence?

�49

ResourceThread ImageCache Client

CmdReceiver

Decoder1 Decodern

Legend: shared channel linear channel

ImageCache:

ImgCacheCmd = N{RequestImage : string ! Requester ( ImgCacheCmd,Exit : � {Running : ImgCacheCmd,

Done : ResourceThread⌦ 1}}

string ! Requester ( ImgCacheCmd

Exit

protocol violated!

Page 142: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Idea: equi-synchronizing

�50

Page 143: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Idea: equi-synchronizing

�50

In addition to imposing acquire-release on shared channels, shared channels must be equi-synchronizing:

Page 144: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Idea: equi-synchronizing

�50

i.e., shared channels must be released back to the same type at which they were acquired, if released.

In addition to imposing acquire-release on shared channels, shared channels must be equi-synchronizing:

Page 145: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Idea: equi-synchronizing

�50

i.e., shared channels must be released back to the same type at which they were acquired, if released.

In addition to imposing acquire-release on shared channels, shared channels must be equi-synchronizing:

ImgCacheCmd = N{RequestImage : string ! Requester ( ImgCacheCmd,Exit : � {Done : ResourceThread⌦ 1,

Running : ImgCacheCmd}}

Page 146: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Idea: equi-synchronizing

�50

i.e., shared channels must be released back to the same type at which they were acquired, if released.

In addition to imposing acquire-release on shared channels, shared channels must be equi-synchronizing:

acquire

ImgCacheCmd = N{RequestImage : string ! Requester ( ImgCacheCmd,Exit : � {Done : ResourceThread⌦ 1,

Running : ImgCacheCmd}}

Page 147: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Idea: equi-synchronizing

�50

i.e., shared channels must be released back to the same type at which they were acquired, if released.

In addition to imposing acquire-release on shared channels, shared channels must be equi-synchronizing:

acquire

ImgCacheCmd = N{RequestImage : string ! Requester ( ImgCacheCmd,Exit : � {Done : ResourceThread⌦ 1,

Running : ImgCacheCmd}}

release

Page 148: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Idea: equi-synchronizing

�50

i.e., shared channels must be released back to the same type at which they were acquired, if released.

In addition to imposing acquire-release on shared channels, shared channels must be equi-synchronizing:

acquire

ImgCacheCmd = N{RequestImage : string ! Requester ( ImgCacheCmd,Exit : � {Done : ResourceThread⌦ 1,

Running : ImgCacheCmd}}

release✓

Page 149: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Idea: equi-synchronizing

�50

i.e., shared channels must be released back to the same type at which they were acquired, if released.

In addition to imposing acquire-release on shared channels, shared channels must be equi-synchronizing:

acquire

ImgCacheCmd = N{RequestImage : string ! Requester ( ImgCacheCmd,Exit : � {Done : ResourceThread⌦ 1,

Running : ImgCacheCmd}}

release

release

Page 150: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Idea: equi-synchronizing

�50

i.e., shared channels must be released back to the same type at which they were acquired, if released.

In addition to imposing acquire-release on shared channels, shared channels must be equi-synchronizing:

acquire

ImgCacheCmd = N{RequestImage : string ! Requester ( ImgCacheCmd,Exit : � {Done : ResourceThread⌦ 1,

Running : ImgCacheCmd}}

release

release

Page 151: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Idea: equi-synchronizing

�50

i.e., shared channels must be released back to the same type at which they were acquired, if released.

In addition to imposing acquire-release on shared channels, shared channels must be equi-synchronizing:

acquire

ImgCacheCmd = N{RequestImage : string ! Requester ( ImgCacheCmd,Exit : � {Done : ResourceThread⌦ 1,

Running : ImgCacheCmd}}

release

release

release ✓

Page 152: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Idea: equi-synchronizing

�50

i.e., shared channels must be released back to the same type at which they were acquired, if released.

In addition to imposing acquire-release on shared channels, shared channels must be equi-synchronizing:

acquire

ImgCacheCmd = N{RequestImage : string ! Requester ( ImgCacheCmd,Exit : � {Done : ResourceThread⌦ 1,

Running : ImgCacheCmd}}

release

release

release ✓✗

Page 153: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Taking stock

�51

Page 154: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Taking stock

�51

Acquire-release + equi-synchronizing:

Page 155: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Taking stock

�51

Acquire-release + equi-synchronizing:

restore protocol adherence;

Page 156: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Taking stock

�51

Acquire-release + equi-synchronizing:

restore protocol adherence;

guarantee freedom of (high-level) data races because execution between acquire-release is atomic.

Page 157: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Taking stock

�51

Acquire-release + equi-synchronizing:

restore protocol adherence;

guarantee freedom of (high-level) data races because execution between acquire-release is atomic.

We could state the policy of acquire-release and equi-synchronizing as a programming methodology.

Page 158: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Taking stock

�51

Acquire-release + equi-synchronizing:

restore protocol adherence;

guarantee freedom of (high-level) data races because execution between acquire-release is atomic.

We could state the policy of acquire-release and equi-synchronizing as a programming methodology.

But, why not lift this policy to the type level and have it enforced statically?

Page 159: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Manifest sharing

�52

Page 160: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Manifest sharing

�52

Page 161: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Manifest sharing

�52

acquire

ImgCacheCmd = N{RequestImage : string ! Requester ( ImgCacheCmd,Exit : � {Done : ResourceThread⌦ 1,

Running : ImgCacheCmd}}

release

release

Page 162: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Manifest sharing

�52

acquire

ImgCacheCmd = N{RequestImage : string ! Requester ( ImgCacheCmd,Exit : � {Done : ResourceThread⌦ 1,

Running : ImgCacheCmd}}

release

release

Legend: shared phase linear phase

Page 163: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Manifest sharing

�53

Page 164: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Manifest sharing

�53

Stratify session types into a linear and shared layer

Page 165: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Manifest sharing

�53

AS � ↑SLAL

AL,BL � ⊕{l ∶ AL} � AL ⊗BL � 1 � ∃x∶AS.BL �N{l ∶ AL} � AL � BL � ↓SLAS � ⇧x∶AS.BL

Stratify session types into a linear and shared layer

Page 166: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Manifest sharing

�53

AS � ↑SLAL

AL,BL � ⊕{l ∶ AL} � AL ⊗BL � 1 � ∃x∶AS.BL �N{l ∶ AL} � AL � BL � ↓SLAS � ⇧x∶AS.BL

Stratify session types into a linear and shared layer

Connect layers with modalities going back and forth

Page 167: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Manifest sharing

�53

AS � ↑SLAL

AL,BL � ⊕{l ∶ AL} � AL ⊗BL � 1 � ∃x∶AS.BL �N{l ∶ AL} � AL � BL � ↓SLAS � ⇧x∶AS.BL

Stratify session types into a linear and shared layer

Connect layers with modalities going back and forth

Page 168: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Manifest sharing

�53

AS � ↑SLAL

AL,BL � ⊕{l ∶ AL} � AL ⊗BL � 1 � ∃x∶AS.BL �N{l ∶ AL} � AL � BL � ↓SLAS � ⇧x∶AS.BL

Stratify session types into a linear and shared layer

Connect layers with modalities going back and forth

Support communication of shared channels

Page 169: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Manifest sharing

�53

AS � ↑SLAL

AL,BL � ⊕{l ∶ AL} � AL ⊗BL � 1 � ∃x∶AS.BL �N{l ∶ AL} � AL � BL � ↓SLAS � ⇧x∶AS.BL

Stratify session types into a linear and shared layer

Connect layers with modalities going back and forth

Support communication of shared channels

Page 170: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Manifest sharing

�54

AS � ↑SLAL

AL,BL � ⊕{l ∶ AL} � AL ⊗BL � 1 � ∃x∶AS.BL �N{l ∶ AL} � AL � BL � ↓SLAS � ⇧x∶AS.BL

Page 171: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Manifest sharing

�54

AS � ↑SLAL

AL,BL � ⊕{l ∶ AL} � AL ⊗BL � 1 � ∃x∶AS.BL �N{l ∶ AL} � AL � BL � ↓SLAS � ⇧x∶AS.BL

ImgCacheCmd = "S

L N{RequestImage : string ! Requester ( #S

L ImgCacheCmd,

Exit : � {Done : ResourceThread⌦ 1,

Running : #S

L ImgCacheCmd}}

Page 172: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Manifest sharing

�54

AS � ↑SLAL

AL,BL � ⊕{l ∶ AL} � AL ⊗BL � 1 � ∃x∶AS.BL �N{l ∶ AL} � AL � BL � ↓SLAS � ⇧x∶AS.BL

ImgCacheCmd = "S

L N{RequestImage : string ! Requester ( #S

L ImgCacheCmd,

Exit : � {Done : ResourceThread⌦ 1,

Running : #S

L ImgCacheCmd}}

Page 173: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Manifest sharing

�54

AS � ↑SLAL

AL,BL � ⊕{l ∶ AL} � AL ⊗BL � 1 � ∃x∶AS.BL �N{l ∶ AL} � AL � BL � ↓SLAS � ⇧x∶AS.BL

ImgCacheCmd = "S

L N{RequestImage : string ! Requester ( #S

L ImgCacheCmd,

Exit : � {Done : ResourceThread⌦ 1,

Running : #S

L ImgCacheCmd}}

Page 174: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Manifest sharing

�54

AS � ↑SLAL

AL,BL � ⊕{l ∶ AL} � AL ⊗BL � 1 � ∃x∶AS.BL �N{l ∶ AL} � AL � BL � ↓SLAS � ⇧x∶AS.BL

Up and down shifts denote acquire and release, resp.

ImgCacheCmd = "S

L N{RequestImage : string ! Requester ( #S

L ImgCacheCmd,

Exit : � {Done : ResourceThread⌦ 1,

Running : #S

L ImgCacheCmd}}

Page 175: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Typing judgments

�55

AS � ↑SLAL

AL,BL � ⊕{l ∶ AL} � AL ⊗BL � 1 � ∃x∶AS.BL �N{l ∶ AL} � AL � BL � ↓SLAS � ⇧x∶AS.BL

Page 176: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Typing judgments

�55

AS � ↑SLAL

AL,BL � ⊕{l ∶ AL} � AL ⊗BL � 1 � ∃x∶AS.BL �N{l ∶ AL} � AL � BL � ↓SLAS � ⇧x∶AS.BL

Based on correspondence between intuitionistic linear logic and session-typed pi-calculus:

Page 177: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Typing judgments

�55

�; � �⌃ P ∶∶ (xL ∶ AL)� �⌃ P ∶∶ (xS ∶ AS)

AS � ↑SLAL

AL,BL � ⊕{l ∶ AL} � AL ⊗BL � 1 � ∃x∶AS.BL �N{l ∶ AL} � AL � BL � ↓SLAS � ⇧x∶AS.BL

Based on correspondence between intuitionistic linear logic and session-typed pi-calculus:

Page 178: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Typing judgments

�55

�; � �⌃ P ∶∶ (xL ∶ AL)� �⌃ P ∶∶ (xS ∶ AS)

AS � ↑SLAL

AL,BL � ⊕{l ∶ AL} � AL ⊗BL � 1 � ∃x∶AS.BL �N{l ∶ AL} � AL � BL � ↓SLAS � ⇧x∶AS.BL

Based on correspondence between intuitionistic linear logic and session-typed pi-calculus:

“Process P provides session of type Am along xm using channels in (� and) �.”

Page 179: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Typing judgments

�55

�; � �⌃ P ∶∶ (xL ∶ AL)� �⌃ P ∶∶ (xS ∶ AS)

AS � ↑SLAL

AL,BL � ⊕{l ∶ AL} � AL ⊗BL � 1 � ∃x∶AS.BL �N{l ∶ AL} � AL � BL � ↓SLAS � ⇧x∶AS.BL

Based on correspondence between intuitionistic linear logic and session-typed pi-calculus:

“Process P provides session of type Am along xm using channels in (� and) �.”

shared (structural) context

Page 180: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Typing judgments

�56

�; � �⌃ P ∶∶ (xL ∶ AL)� �⌃ P ∶∶ (xS ∶ AS)

AS � ↑SLAL

AL,BL � ⊕{l ∶ AL} � AL ⊗BL � 1 � ∃x∶AS.BL �N{l ∶ AL} � AL � BL � ↓SLAS � ⇧x∶AS.BL

Based on correspondence between intuitionistic linear logic and session-typed pi-calculus:

“Process P provides session of type Am along xm using channels in (� and) �.”

Page 181: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Typing judgments

�56

�; � �⌃ P ∶∶ (xL ∶ AL)� �⌃ P ∶∶ (xS ∶ AS)

AS � ↑SLAL

AL,BL � ⊕{l ∶ AL} � AL ⊗BL � 1 � ∃x∶AS.BL �N{l ∶ AL} � AL � BL � ↓SLAS � ⇧x∶AS.BL

Based on correspondence between intuitionistic linear logic and session-typed pi-calculus:

“Process P provides session of type Am along xm using channels in (� and) �.”

linear (substructural) context

Page 182: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Typing of acquire

�57

Page 183: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Typing of acquire

�57

�, xS ∶↑SL AL; �, xL ∶ AL �⌃ QxL ∶∶ (zL ∶ CL)�, xS ∶↑SL AL; � �⌃ xL ← acquire xS ;QxL ∶∶ (zL ∶ CL) (T-↑SLL)

Page 184: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Typing of acquire

�57

�, xS ∶↑SL AL; �, xL ∶ AL �⌃ QxL ∶∶ (zL ∶ CL)�, xS ∶↑SL AL; � �⌃ xL ← acquire xS ;QxL ∶∶ (zL ∶ CL) (T-↑SLL)

Page 185: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Typing of acquire

�57

�, xS ∶↑SL AL; �, xL ∶ AL �⌃ QxL ∶∶ (zL ∶ CL)�, xS ∶↑SL AL; � �⌃ xL ← acquire xS ;QxL ∶∶ (zL ∶ CL) (T-↑SLL)

�; ⋅ �⌃ PxL ∶∶ (xL ∶ AL)� �⌃ xL ← accept xS ;PxL ∶∶ (xS ∶↑SL AL) (T-↑SLR)

Page 186: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Typing of acquire

�57

�, xS ∶↑SL AL; �, xL ∶ AL �⌃ QxL ∶∶ (zL ∶ CL)�, xS ∶↑SL AL; � �⌃ xL ← acquire xS ;QxL ∶∶ (zL ∶ CL) (T-↑SLL)

�; ⋅ �⌃ PxL ∶∶ (xL ∶ AL)� �⌃ xL ← accept xS ;PxL ∶∶ (xS ∶↑SL AL) (T-↑SLR)

Page 187: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Typing of release

�58

Page 188: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Typing of release

�58

�, xS ∶ AS; � �⌃ QxS ∶∶ (zL ∶ CL)�; �, xL ∶↓SL AS �⌃ xS ← release xL ;QxS ∶∶ (zL ∶ CL) (T-↓SLL)

Page 189: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Typing of release

�58

�, xS ∶ AS; � �⌃ QxS ∶∶ (zL ∶ CL)�; �, xL ∶↓SL AS �⌃ xS ← release xL ;QxS ∶∶ (zL ∶ CL) (T-↓SLL)

Page 190: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Typing of release

�58

�, xS ∶ AS; � �⌃ QxS ∶∶ (zL ∶ CL)�; �, xL ∶↓SL AS �⌃ xS ← release xL ;QxS ∶∶ (zL ∶ CL) (T-↓SLL)

� �⌃ PxS ∶∶ (xS ∶ AS)�; ⋅ �⌃ xS ← detach xL ;PxS ∶∶ (xL ∶↓SL AS) (T-↓SLR)

Page 191: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Typing of release

�58

�, xS ∶ AS; � �⌃ QxS ∶∶ (zL ∶ CL)�; �, xL ∶↓SL AS �⌃ xS ← release xL ;QxS ∶∶ (zL ∶ CL) (T-↓SLL)

� �⌃ PxS ∶∶ (xS ∶ AS)�; ⋅ �⌃ xS ← detach xL ;PxS ∶∶ (xL ∶↓SL AS) (T-↓SLR)

Page 192: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Taking stock

�59

Page 193: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Taking stock

�59

We have a session type system that allows shared and linear channels to coexist and guarantees:

data-race-freedom (low-level and high-level)

protocol adherence

Page 194: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Taking stock

�59

We have a session type system that allows shared and linear channels to coexist and guarantees:

data-race-freedom (low-level and high-level)

protocol adherence

What about deadlock-freedom?

Page 195: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Why are linear session types deadlock-free?

�60

Page 196: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Why are linear session types deadlock-free?

�60

Linearity (“exactly one client”) turns process graph into a tree.

Page 197: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Why are linear session types deadlock-free?

�60

a

b c d

e f g

parent: client

child: provider

Linearity (“exactly one client”) turns process graph into a tree.

Legend: linear channel

Page 198: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Why are linear session types deadlock-free?

�61

a

b c d

e f g

Legend: linear channel

Linearity (“exactly one client”) turns process graph into a tree.

Page 199: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Why are linear session types deadlock-free?

What are the threats to progress?

�61

a

b c d

e f g

Legend: linear channel

Linearity (“exactly one client”) turns process graph into a tree.

Page 200: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Why are linear session types deadlock-free?

What are the threats to progress?• Two scenarios:

�61

a

b c d

e f g

Legend: linear channel

Linearity (“exactly one client”) turns process graph into a tree.

Page 201: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Why are linear session types deadlock-free?

What are the threats to progress?• Two scenarios:

• provider ready to synchronize, client not

�61

a

b c d

e f g

Legend: linear channel

Linearity (“exactly one client”) turns process graph into a tree.

Page 202: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Why are linear session types deadlock-free?

What are the threats to progress?• Two scenarios:

• provider ready to synchronize, client not• client ready to synchronize, provider not

�61

a

b c d

e f g

Legend: linear channel

Linearity (“exactly one client”) turns process graph into a tree.

Page 203: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Why are linear session types deadlock-free?

What are the threats to progress?• Two scenarios:

• provider ready to synchronize, client not• client ready to synchronize, provider not

• Let’s visualize this waiting dependency with a green arrow

�61

a

b c d

e f g

Legend: linear channel

Linearity (“exactly one client”) turns process graph into a tree.

Page 204: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Why are linear session types deadlock-free?

What are the threats to progress?• Two scenarios:

• provider ready to synchronize, client not• client ready to synchronize, provider not

• Let’s visualize this waiting dependency with a green arrow

�61

a

b c d

e f g

Legend: linear channel a b “a waits for b”

Linearity (“exactly one client”) turns process graph into a tree.

Page 205: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Why are linear session types deadlock-free?

What are the threats to progress?• Two scenarios:

• provider ready to synchronize, client not• client ready to synchronize, provider not

• Let’s visualize this waiting dependency with a green arrow

�61

a

b c d

e f g

Legend: linear channel a b “a waits for b”

Linearity (“exactly one client”) turns process graph into a tree.

Page 206: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Why are linear session types deadlock-free?

What are the threats to progress?• Two scenarios:

• provider ready to synchronize, client not• client ready to synchronize, provider not

• Let’s visualize this waiting dependency with a green arrow

�61

a

b c d

e f g

Legend: linear channel a b “a waits for b”

No green cycles: green arrows can only go along linear channels, and client and provider cannot both be waiting for each other.

Linearity (“exactly one client”) turns process graph into a tree.

Page 207: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Let’s add sharing

�62

Page 208: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Let’s add sharing

�62

We get a graph of linear and shared processes, with a linear tree inside.

Page 209: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Let’s add sharing

�62

a

b c d

e f g

We get a graph of linear and shared processes, with a linear tree inside.

Legend: linear channel linear process

shared channel

shared process

Page 210: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Let’s add sharing

�62

a

b c d

e f g

We get a graph of linear and shared processes, with a linear tree inside.

Legend: linear channel linear process

shared channel

shared process

Page 211: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Let’s add sharing

�63

a

b c d

e f g

We get a graph of linear and shared processes, with a linear tree inside.

Legend: linear channel linear process

shared channel

shared process

Page 212: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Let’s add sharing

�63

a

b c d

e f g

We get a graph of linear and shared processes, with a linear tree inside.

Legend: linear channel linear process

shared channel

shared process

Acquire-release amounts to “locking”

Page 213: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Let’s add sharing

�63

a

b c d

e f g

We get a graph of linear and shared processes, with a linear tree inside.

Legend: linear channel linear process

shared channel

shared process

Acquire-release amounts to “locking”• Possibility of cyclic dependencies

Page 214: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Let’s add sharing

�63

a

b c d

e f g

We get a graph of linear and shared processes, with a linear tree inside.

Legend: linear channel linear process

shared channel

shared process

Acquire-release amounts to “locking”• Possibility of cyclic dependencies• Let’s visualize this waiting dependency

with a red arrow

Page 215: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Let’s add sharing

�63

a

b c d

e f g

We get a graph of linear and shared processes, with a linear tree inside.

Legend: linear channel linear process

shared channel

shared process

Acquire-release amounts to “locking”• Possibility of cyclic dependencies• Let’s visualize this waiting dependency

with a red arrow

a b “a waits for b to release resource”

Page 216: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Let’s add sharing

�63

a

b c d

e f g

We get a graph of linear and shared processes, with a linear tree inside.

Legend: linear channel linear process

shared channel

shared process

Acquire-release amounts to “locking”• Possibility of cyclic dependencies• Let’s visualize this waiting dependency

with a red arrow

a b “a waits for b to release resource”

Page 217: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Let’s add sharing

�63

a

b c d

e f g

We get a graph of linear and shared processes, with a linear tree inside.

Legend: linear channel linear process

shared channel

shared process

Acquire-release amounts to “locking”• Possibility of cyclic dependencies• Let’s visualize this waiting dependency

with a red arrow

a b “a waits for b to release resource”

Page 218: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Let’s add sharing

�63

a

b c d

e f g

We get a graph of linear and shared processes, with a linear tree inside.

Legend: linear channel linear process

shared channel

shared process

Acquire-release amounts to “locking”• Possibility of cyclic dependencies• Let’s visualize this waiting dependency

with a red arrow

a b “a waits for b to release resource”

Page 219: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Let’s add sharing

�63

a

b c d

e f g

We get a graph of linear and shared processes, with a linear tree inside.

Legend: linear channel linear process

shared channel

shared process

Acquire-release amounts to “locking”• Possibility of cyclic dependencies• Let’s visualize this waiting dependency

with a red arrow• Note: red arrows can connect arbitrary

nodes

a b “a waits for b to release resource”

Page 220: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Can we re-establish deadlock-freedom?

�64

Page 221: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Can we re-establish deadlock-freedom?

An enticing solution: “locking up” • Impose a partial order on resources. • Ensure that resources are acquired (“locked”) in increasing order.

�64

Page 222: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Can we re-establish deadlock-freedom?

An enticing solution: “locking up” • Impose a partial order on resources. • Ensure that resources are acquired (“locked”) in increasing order.

�64

However, cyclic dependencies between acquire requests are not the only source of deadlock!

Page 223: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Can we re-establish deadlock-freedom?

An enticing solution: “locking up” • Impose a partial order on resources. • Ensure that resources are acquired (“locked”) in increasing order.

�64

However, cyclic dependencies between acquire requests are not the only source of deadlock!

Two Forms of waiting dependencies:

Page 224: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Can we re-establish deadlock-freedom?

An enticing solution: “locking up” • Impose a partial order on resources. • Ensure that resources are acquired (“locked”) in increasing order.

�64

However, cyclic dependencies between acquire requests are not the only source of deadlock!

Two Forms of waiting dependencies:• waiting to synchronize: a b “a waits for b to synchronize”

Page 225: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Can we re-establish deadlock-freedom?

An enticing solution: “locking up” • Impose a partial order on resources. • Ensure that resources are acquired (“locked”) in increasing order.

�64

However, cyclic dependencies between acquire requests are not the only source of deadlock!

Two Forms of waiting dependencies:• waiting to synchronize:• waiting to release:

a b “a waits for b to synchronize”a b “a waits for b to release resource”

Page 226: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Can we re-establish deadlock-freedom?

�65

Two Forms of waiting dependencies: • waiting to synchronize: • waiting to release:

a b “a waits for b to synchronize”a b “a waits for b to release resource”

Page 227: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Can we re-establish deadlock-freedom?

�65

Two Forms of waiting dependencies: • waiting to synchronize: • waiting to release:

a b “a waits for b to synchronize”a b “a waits for b to release resource”

a

b c d

e f g

Page 228: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Can we re-establish deadlock-freedom?

�65

Two Forms of waiting dependencies: • waiting to synchronize: • waiting to release:

a b “a waits for b to synchronize”a b “a waits for b to release resource”

a

b c d

e f g

a

b d d

e f g

Page 229: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Can we re-establish deadlock-freedom?

�65

Two Forms of waiting dependencies: • waiting to synchronize: • waiting to release:

a b “a waits for b to synchronize”a b “a waits for b to release resource”

a

b c d

e f g

a

b d d

e f g

Cycles can consist of red arrows only or a combination of red and green arrows.

Page 230: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Idea: competitors and collaborators

�66

Page 231: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Idea: competitors and collaborators

�66

Competitors: overlap in set of resources acquired

Page 232: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Idea: competitors and collaborators

�66

Competitors: overlap in set of resources acquired

Collaborators: do not overlap in set of resources acquired

Page 233: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Idea: competitors and collaborators

�66

Notice: a resource acquired becomes a child of the acquirer

Competitors: overlap in set of resources acquired

Collaborators: do not overlap in set of resources acquired

Page 234: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Idea: competitors and collaborators

�66

a

Notice: a resource acquired becomes a child of the acquirer

b c

12

Competitors: overlap in set of resources acquired

Collaborators: do not overlap in set of resources acquired

Page 235: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Idea: competitors and collaborators

�67

a

Notice: a resource acquired becomes a child of the acquirer

b c

1

2

Competitors: overlap in set of resources acquired

Collaborators: do not overlap in set of resources acquired

Page 236: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Idea: competitors and collaborators

�68

a

Notice: a resource acquired becomes a child of the acquirer

b c

1 2

Competitors: overlap in set of resources acquired

Collaborators: do not overlap in set of resources acquired

Page 237: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Idea: competitors and collaborators

�69

a

Notice: a resource acquired becomes a child of the acquirer

b c

1 2

Competitors: overlap in set of resources acquired

Collaborators: do not overlap in set of resources acquired

competitors tend to be siblings

Page 238: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Idea: competitors and collaborators

�69

a

Notice: a resource acquired becomes a child of the acquirer

b c

1 2

Competitors: overlap in set of resources acquired

Collaborators: do not overlap in set of resources acquired

competitors tend to be siblings

{b, c}

Page 239: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Idea: competitors and collaborators

�69

a

Notice: a resource acquired becomes a child of the acquirer

b c

1 2

Competitors: overlap in set of resources acquired

Collaborators: do not overlap in set of resources acquired

collaborators tend to be in the same branch

competitors tend to be siblings

{b, c}

Page 240: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Idea: competitors and collaborators

�69

a

Notice: a resource acquired becomes a child of the acquirer

b c

1 2

Competitors: overlap in set of resources acquired

Collaborators: do not overlap in set of resources acquired

collaborators tend to be in the same branch

competitors tend to be siblings

{a, b, 1} {a, b, 2} {a, c}

{b, c}

Page 241: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Manifest deadlock-freedom

�70

Page 242: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Manifest deadlock-freedom

�70

Define type system enforcing the following invariants:

collaborators

a

b c

1 2

competitors

Page 243: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Manifest deadlock-freedom

�70

Define type system enforcing the following invariants:

collaborators

a

b c

1 2

competitors

competitors employ locking-up for resources they compete forA

Page 244: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Manifest deadlock-freedom

�70

Define type system enforcing the following invariants:

collaborators

a

b c

1 2

competitors

collaborators acquire mutually disjoint sets of resourcesB

competitors employ locking-up for resources they compete forA

Page 245: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Manifest deadlock-freedom

�70

Define type system enforcing the following invariants:

collaborators

a

b c

1 2

competitors

collaborators acquire mutually disjoint sets of resourcesB

competitors employ locking-up for resources they compete forA

competitors have released all acquired resources when synchronizing with other competitors (“tallking-up”)

C

Page 246: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Manifest deadlock-freedom

�70

Define type system enforcing the following invariants:

collaborators

a

b c

1 2

competitors

collaborators acquire mutually disjoint sets of resourcesB

competitors employ locking-up for resources they compete forA

competitors have released all acquired resources when synchronizing with other competitors (“tallking-up”)

C

A rules out red-arrow cycles, B and C rule out red-green-arrow cycles.

Page 247: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Manifest deadlock-freedom

�71

Page 248: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Manifest deadlock-freedom

�71

Introduce a world, an abstract value equipped with a partial order.

Page 249: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Manifest deadlock-freedom

�71

Every process invariantly resides at a world.

Introduce a world, an abstract value equipped with a partial order.

Page 250: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Manifest deadlock-freedom

�71

Every process invariantly resides at a world.

Every process indicates the range of worlds it may acquire.

Introduce a world, an abstract value equipped with a partial order.

Page 251: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Manifest deadlock-freedom

�71

Every process invariantly resides at a world.

Every process indicates the range of worlds it may acquire.

Introduce a world, an abstract value equipped with a partial order.

; � `⌃ P :: (xS : AS[!kl!n!l

]) (where + irreflexive)

; �; �; � `⌃ P :: (xL : AL[!kl!n!l

]) (where + irreflexive)

Page 252: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Manifest deadlock-freedom

�71

Every process invariantly resides at a world.

Every process indicates the range of worlds it may acquire.

Introduce a world, an abstract value equipped with a partial order.

; � `⌃ P :: (xS : AS[!kl!n!l

]) (where + irreflexive)

; �; �; � `⌃ P :: (xL : AL[!kl!n!l

]) (where + irreflexive)

Page 253: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Manifest deadlock-freedom

�71

Every process invariantly resides at a world.

Every process indicates the range of worlds it may acquire.

Introduce a world, an abstract value equipped with a partial order.

; � `⌃ P :: (xS : AS[!kl!n!l

]) (where + irreflexive)

; �; �; � `⌃ P :: (xL : AL[!kl!n!l

]) (where + irreflexive)

worlds associated with process

Page 254: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Manifest deadlock-freedom

�72

Every process invariantly resides at a world.

Every process indicates the range of worlds it may acquire.

Introduce a world, an abstract value equipped with a partial order.

; � `⌃ P :: (xS : AS[!kl!n!l

]) (where + irreflexive)

; �; �; � `⌃ P :: (xL : AL[!kl!n!l

]) (where + irreflexive)

Page 255: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Manifest deadlock-freedom

�72

Every process invariantly resides at a world.

Every process indicates the range of worlds it may acquire.

Introduce a world, an abstract value equipped with a partial order.

; � `⌃ P :: (xS : AS[!kl!n!l

]) (where + irreflexive)

; �; �; � `⌃ P :: (xL : AL[!kl!n!l

]) (where + irreflexive)

Page 256: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Manifest deadlock-freedom

�72

Every process invariantly resides at a world.

Every process indicates the range of worlds it may acquire.

Introduce a world, an abstract value equipped with a partial order.

; � `⌃ P :: (xS : AS[!kl!n!l

]) (where + irreflexive)

; �; �; � `⌃ P :: (xL : AL[!kl!n!l

]) (where + irreflexive)

self-world: world at which process

resides

Page 257: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Manifest deadlock-freedom

�73

Every process invariantly resides at a world.

Every process indicates the range of worlds it may acquire.

Introduce a world, an abstract value equipped with a partial order.

; � `⌃ P :: (xS : AS[!kl!n!l

]) (where + irreflexive)

; �; �; � `⌃ P :: (xL : AL[!kl!n!l

]) (where + irreflexive)

Page 258: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Manifest deadlock-freedom

�73

Every process invariantly resides at a world.

Every process indicates the range of worlds it may acquire.

Introduce a world, an abstract value equipped with a partial order.

; � `⌃ P :: (xS : AS[!kl!n!l

]) (where + irreflexive)

; �; �; � `⌃ P :: (xL : AL[!kl!n!l

]) (where + irreflexive)

Page 259: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Manifest deadlock-freedom

�73

Every process invariantly resides at a world.

Every process indicates the range of worlds it may acquire.

Introduce a world, an abstract value equipped with a partial order.

; � `⌃ P :: (xS : AS[!kl!n!l

]) (where + irreflexive)

; �; �; � `⌃ P :: (xL : AL[!kl!n!l

]) (where + irreflexive)

min-world: world of minimal resource

to be acquired

Page 260: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Manifest deadlock-freedom

�74

Every process invariantly resides at a world.

Every process indicates the range of worlds it may acquire.

Introduce a world, an abstract value equipped with a partial order.

; � `⌃ P :: (xS : AS[!kl!n!l

]) (where + irreflexive)

; �; �; � `⌃ P :: (xL : AL[!kl!n!l

]) (where + irreflexive)

Page 261: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Manifest deadlock-freedom

�74

Every process invariantly resides at a world.

Every process indicates the range of worlds it may acquire.

Introduce a world, an abstract value equipped with a partial order.

; � `⌃ P :: (xS : AS[!kl!n!l

]) (where + irreflexive)

; �; �; � `⌃ P :: (xL : AL[!kl!n!l

]) (where + irreflexive)

Page 262: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Manifest deadlock-freedom

�74

Every process invariantly resides at a world.

Every process indicates the range of worlds it may acquire.

Introduce a world, an abstract value equipped with a partial order.

; � `⌃ P :: (xS : AS[!kl!n!l

]) (where + irreflexive)

; �; �; � `⌃ P :: (xL : AL[!kl!n!l

]) (where + irreflexive)

max-world: world of maximal resource to be

acquired

Page 263: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Manifest deadlock-freedom

�75

Every process invariantly resides at a world.

Every process indicates the range of worlds it may acquire.

Introduce a world, an abstract value equipped with a partial order.

; � `⌃ P :: (xS : AS[!kl!n!l

]) (where + irreflexive)

; �; �; � `⌃ P :: (xL : AL[!kl!n!l

]) (where + irreflexive)

Page 264: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Manifest deadlock-freedom

�75

Every process invariantly resides at a world.

Every process indicates the range of worlds it may acquire.

Introduce a world, an abstract value equipped with a partial order.

; � `⌃ P :: (xS : AS[!kl!n!l

]) (where + irreflexive)

; �; �; � `⌃ P :: (xL : AL[!kl!n!l

]) (where + irreflexive)

Page 265: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Manifest deadlock-freedom

�75

Every process invariantly resides at a world.

Every process indicates the range of worlds it may acquire.

Introduce a world, an abstract value equipped with a partial order.

; � `⌃ P :: (xS : AS[!kl!n!l

]) (where + irreflexive)

; �; �; � `⌃ P :: (xL : AL[!kl!n!l

]) (where + irreflexive)

world order

Page 266: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Manifest deadlock-freedom

�76

Every process invariantly resides at a world.

Every process indicates the range of worlds it may acquire.

Introduce a world, an abstract value equipped with a partial order.

; � `⌃ P :: (xS : AS[!kl!n!l

]) (where + irreflexive)

; �; �; � `⌃ P :: (xL : AL[!kl!n!l

]) (where + irreflexive)

Page 267: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Manifest deadlock-freedom

�76

Every process invariantly resides at a world.

Every process indicates the range of worlds it may acquire.

Introduce a world, an abstract value equipped with a partial order.

; � `⌃ P :: (xS : AS[!kl!n!l

]) (where + irreflexive)

; �; �; � `⌃ P :: (xL : AL[!kl!n!l

]) (where + irreflexive)

Page 268: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Manifest deadlock-freedom

�76

Every process invariantly resides at a world.

Every process indicates the range of worlds it may acquire.

Introduce a world, an abstract value equipped with a partial order.

; � `⌃ P :: (xS : AS[!kl!n!l

]) (where + irreflexive)

; �; �; � `⌃ P :: (xL : AL[!kl!n!l

]) (where + irreflexive)

possibly “aliased” linear channels

Page 269: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Manifest deadlock-freedom

�77

; � `⌃ P :: (xS : AS[!kl!n!l

]) (where + irreflexive)

; �; �; � `⌃ P :: (xL : AL[!kl!n!l

]) (where + irreflexive)

Page 270: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Manifest deadlock-freedom

�77

; � `⌃ P :: (xS : AS[!kl!n!l

]) (where + irreflexive)

; �; �; � `⌃ P :: (xL : AL[!kl!n!l

]) (where + irreflexive)

Express invariants A, B, and C in terms of:

Page 271: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Manifest deadlock-freedom

�77

; � `⌃ P :: (xS : AS[!kl!n!l

]) (where + irreflexive)

; �; �; � `⌃ P :: (xL : AL[!kl!n!l

]) (where + irreflexive)

Express invariants A, B, and C in terms of:

min(parent) ≤ self(acquired_child) ≤ max(parent)

Page 272: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Manifest deadlock-freedom

�77

; � `⌃ P :: (xS : AS[!kl!n!l

]) (where + irreflexive)

; �; �; � `⌃ P :: (xL : AL[!kl!n!l

]) (where + irreflexive)

Express invariants A, B, and C in terms of:

min(parent) ≤ self(acquired_child) ≤ max(parent)

max(parent) < min(child)

Page 273: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Manifest deadlock-freedom

�77

; � `⌃ P :: (xS : AS[!kl!n!l

]) (where + irreflexive)

; �; �; � `⌃ P :: (xL : AL[!kl!n!l

]) (where + irreflexive)

Express invariants A, B, and C in terms of:

min(parent) ≤ self(acquired_child) ≤ max(parent)

max(parent) < min(child)

collaborators

a

b c

1 2

competitors

no vertical red arrows

Page 274: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Manifest deadlock-freedom

�78

; � `⌃ P :: (xS : AS[!kl!n!l

]) (where + irreflexive)

; �; �; � `⌃ P :: (xL : AL[!kl!n!l

]) (where + irreflexive)

Express invariants A, B, and C in terms of:

min(parent) ≤ self(acquired_child) ≤ max(parent)

max(parent) < min(child)

Page 275: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Manifest deadlock-freedom

�78

; � `⌃ P :: (xS : AS[!kl!n!l

]) (where + irreflexive)

; �; �; � `⌃ P :: (xL : AL[!kl!n!l

]) (where + irreflexive)

Express invariants A, B, and C in terms of:

min(parent) ≤ self(acquired_child) ≤ max(parent)

max(parent) < min(child)

for an acquire: lock-up

Page 276: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Manifest deadlock-freedom

�78

; � `⌃ P :: (xS : AS[!kl!n!l

]) (where + irreflexive)

; �; �; � `⌃ P :: (xL : AL[!kl!n!l

]) (where + irreflexive)

Express invariants A, B, and C in terms of:

min(parent) ≤ self(acquired_child) ≤ max(parent)

max(parent) < min(child)

for an acquire: lock-up

collaborators

a

b c

1 2

competitors

no red cycles

Page 277: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Manifest deadlock-freedom

�79

; � `⌃ P :: (xS : AS[!kl!n!l

]) (where + irreflexive)

; �; �; � `⌃ P :: (xL : AL[!kl!n!l

]) (where + irreflexive)

Express invariants A, B, and C in terms of:

min(parent) ≤ self(acquired_child) ≤ max(parent)

max(parent) < min(child)

for an acquire: lock-up

Page 278: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Manifest deadlock-freedom

�79

; � `⌃ P :: (xS : AS[!kl!n!l

]) (where + irreflexive)

; �; �; � `⌃ P :: (xL : AL[!kl!n!l

]) (where + irreflexive)

Express invariants A, B, and C in terms of:

min(parent) ≤ self(acquired_child) ≤ max(parent)

max(parent) < min(child)

for an acquire: lock-up

for right-rule: Φ must be empty

Page 279: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Manifest deadlock-freedom

�79

; � `⌃ P :: (xS : AS[!kl!n!l

]) (where + irreflexive)

; �; �; � `⌃ P :: (xL : AL[!kl!n!l

]) (where + irreflexive)

Express invariants A, B, and C in terms of:

min(parent) ≤ self(acquired_child) ≤ max(parent)

max(parent) < min(child)

for an acquire: lock-up

for right-rule: Φ must be empty

collaborators

a

b c

1 2

competitors

no ingoing red and up-going green arrow

Page 280: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Manifest deadlock-freedom

�80

; � `⌃ P :: (xS : AS[!kl!n!l

]) (where + irreflexive)

; �; �; � `⌃ P :: (xL : AL[!kl!n!l

]) (where + irreflexive)

Express invariants A, B, and C in terms of:

min(parent) ≤ self(acquired_child) ≤ max(parent)

max(parent) < min(child)

for an acquire: lock-up

for right-rule: Φ must be empty

Page 281: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Manifest deadlock-freedom

�80

; � `⌃ P :: (xS : AS[!kl!n!l

]) (where + irreflexive)

; �; �; � `⌃ P :: (xL : AL[!kl!n!l

]) (where + irreflexive)

Express invariants A, B, and C in terms of:

min(parent) ≤ self(acquired_child) ≤ max(parent)

max(parent) < min(child)

for an acquire: lock-up

for right-rule: Φ must be empty

These low-level invariants are enforced by typing.

Page 282: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Taking stock

�81

Page 283: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Taking stock

�81

We have a session type system that allows shared and linear channels to coexist and guarantees:

data-race-freedom (low-level and high-level)

protocol adherence

deadlock-freedom

Page 284: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Taking stock

�81

We have a session type system that allows shared and linear channels to coexist and guarantees:

data-race-freedom (low-level and high-level)

protocol adherence

deadlock-freedom

We have increased practicality of linear session types while maintaining their guarantees.

Page 285: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Current & future work

�82

Page 286: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Digital contracts (with Hoffmann, Pfenning, and Das)

�83

Page 287: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Digital contracts (with Hoffmann, Pfenning, and Das)

�83

Unique application field for shared session types:

Page 288: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Digital contracts (with Hoffmann, Pfenning, and Das)

�83

Unique application field for shared session types:

auction = "S

L � {running : N{bid : id ! money ( #S

Lauction,cancel : #S

Lauction},ended : id ! �{won : lot⌦ #S

Lauction,lost : money ⌦ #S

Lauction}}

Page 289: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Digital contracts (with Hoffmann, Pfenning, and Das)

�83

Unique application field for shared session types:

auction = "S

L � {running : N{bid : id ! money ( #S

Lauction,cancel : #S

Lauction},ended : id ! �{won : lot⌦ #S

Lauction,lost : money ⌦ #S

Lauction}}

Resource analysis for static prediction of execution cost.

Page 290: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Digital contracts (with Hoffmann, Pfenning, and Das)

�83

Unique application field for shared session types:

auction = "S

L � {running : N{bid : id ! money ( #S

Lauction,cancel : #S

Lauction},ended : id ! �{won : lot⌦ #S

Lauction,lost : money ⌦ #S

Lauction}}

Resource analysis for static prediction of execution cost.

Under development: Nomos, a digital contract language based on resource-aware shared session types.

Page 291: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Unifying parallelism and concurrency

�84

Page 292: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Unifying parallelism and concurrency

�84

Shared session types recover expressiveness of untyped asynchronous pi-calculus [Balzer et al. CONCUR 2018]

Page 293: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Unifying parallelism and concurrency

�84

Shared session types recover expressiveness of untyped asynchronous pi-calculus [Balzer et al. CONCUR 2018]

introduce nondeterminism

Page 294: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Unifying parallelism and concurrency

�84

Shared session types recover expressiveness of untyped asynchronous pi-calculus [Balzer et al. CONCUR 2018]

introduce nondeterminism

linear logic session types are deterministic

Page 295: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Unifying parallelism and concurrency

�84

Shared session types recover expressiveness of untyped asynchronous pi-calculus [Balzer et al. CONCUR 2018]

introduce nondeterminism

linear logic session types are deterministic

Opportunity for unifying framework that combines both deterministic (parallel) and nondeterministic (concurrent) computation.

Page 296: Shared Session Types for Safe, Practical Concurrencybalzers/publications/safe_concurrency.pdf · Concurrency is ubiquitous Many programming problems demand concurrency • Flight

Thank you for your attention!

Papers for this talk: • Stephanie Balzer and Frank Pfenning: Manifest Sharing with Session

Types. ICFP 2017. • Stephanie Balzer, Bernardo Toninho, and Frank Pfenning: Manifest

Deadlock-Freedom for Shared Session Types. ESOP 2019. • Stephanie Balzer, Frank Pfenning, and Bernardo Toninho: A Universal

Session Type for Untyped Asynchronous Communication. CONCUR 2019.

�85