topic 4: concurrency

83
4: Concurrency Zubair Nabi [email protected] April 18, 2013 Zubair Nabi 4: Concurrency April 18, 2013 1 / 22

Upload: zubair-nabi

Post on 18-Nov-2014

444 views

Category:

Technology


1 download

DESCRIPTION

Cloud Computing Workshop 2013, ITU

TRANSCRIPT

Page 1: Topic 4: Concurrency

4: Concurrency

Zubair Nabi

[email protected]

April 18, 2013

Zubair Nabi 4: Concurrency April 18, 2013 1 / 22

Page 2: Topic 4: Concurrency

Outline

1 Introduction

2 Concurrency in Practice

3 Liveness

4 Message passing

5 Transactions

Zubair Nabi 4: Concurrency April 18, 2013 2 / 22

Page 3: Topic 4: Concurrency

Outline

1 Introduction

2 Concurrency in Practice

3 Liveness

4 Message passing

5 Transactions

Zubair Nabi 4: Concurrency April 18, 2013 3 / 22

Page 4: Topic 4: Concurrency

Execution

ProcessI Program in execution

I Unit of protection and resource allocationI Private address space and one or more threads

ThreadI An entity managed by the schedulerI Represents an individual execution contextI Runs within the address space of the containing process

Zubair Nabi 4: Concurrency April 18, 2013 4 / 22

Page 5: Topic 4: Concurrency

Execution

ProcessI Program in executionI Unit of protection and resource allocation

I Private address space and one or more threads

ThreadI An entity managed by the schedulerI Represents an individual execution contextI Runs within the address space of the containing process

Zubair Nabi 4: Concurrency April 18, 2013 4 / 22

Page 6: Topic 4: Concurrency

Execution

ProcessI Program in executionI Unit of protection and resource allocationI Private address space and one or more threads

ThreadI An entity managed by the schedulerI Represents an individual execution contextI Runs within the address space of the containing process

Zubair Nabi 4: Concurrency April 18, 2013 4 / 22

Page 7: Topic 4: Concurrency

Execution

ProcessI Program in executionI Unit of protection and resource allocationI Private address space and one or more threads

ThreadI An entity managed by the scheduler

I Represents an individual execution contextI Runs within the address space of the containing process

Zubair Nabi 4: Concurrency April 18, 2013 4 / 22

Page 8: Topic 4: Concurrency

Execution

ProcessI Program in executionI Unit of protection and resource allocationI Private address space and one or more threads

ThreadI An entity managed by the schedulerI Represents an individual execution context

I Runs within the address space of the containing process

Zubair Nabi 4: Concurrency April 18, 2013 4 / 22

Page 9: Topic 4: Concurrency

Execution

ProcessI Program in executionI Unit of protection and resource allocationI Private address space and one or more threads

ThreadI An entity managed by the schedulerI Represents an individual execution contextI Runs within the address space of the containing process

Zubair Nabi 4: Concurrency April 18, 2013 4 / 22

Page 10: Topic 4: Concurrency

Concurrency

Seemingly doing many things at once

With a single processor: Interleaving of different executions1 Process/OS2 Inter-process3 Intra-process

With multiple processorsI True parallelism

Zubair Nabi 4: Concurrency April 18, 2013 5 / 22

Page 11: Topic 4: Concurrency

Concurrency

Seemingly doing many things at onceWith a single processor: Interleaving of different executions

1 Process/OS2 Inter-process3 Intra-process

With multiple processorsI True parallelism

Zubair Nabi 4: Concurrency April 18, 2013 5 / 22

Page 12: Topic 4: Concurrency

Concurrency

Seemingly doing many things at onceWith a single processor: Interleaving of different executions

1 Process/OS

2 Inter-process3 Intra-process

With multiple processorsI True parallelism

Zubair Nabi 4: Concurrency April 18, 2013 5 / 22

Page 13: Topic 4: Concurrency

Concurrency

Seemingly doing many things at onceWith a single processor: Interleaving of different executions

1 Process/OS2 Inter-process

3 Intra-process

With multiple processorsI True parallelism

Zubair Nabi 4: Concurrency April 18, 2013 5 / 22

Page 14: Topic 4: Concurrency

Concurrency

Seemingly doing many things at onceWith a single processor: Interleaving of different executions

1 Process/OS2 Inter-process3 Intra-process

With multiple processorsI True parallelism

Zubair Nabi 4: Concurrency April 18, 2013 5 / 22

Page 15: Topic 4: Concurrency

Concurrency

Seemingly doing many things at onceWith a single processor: Interleaving of different executions

1 Process/OS2 Inter-process3 Intra-process

With multiple processorsI True parallelism

Zubair Nabi 4: Concurrency April 18, 2013 5 / 22

Page 16: Topic 4: Concurrency

Advantages

Overlap computation and I/O

Simplify code structuring

Improve responsiveness

Seamless use of multiple CPUs

Zubair Nabi 4: Concurrency April 18, 2013 6 / 22

Page 17: Topic 4: Concurrency

Advantages

Overlap computation and I/O

Simplify code structuring

Improve responsiveness

Seamless use of multiple CPUs

Zubair Nabi 4: Concurrency April 18, 2013 6 / 22

Page 18: Topic 4: Concurrency

Advantages

Overlap computation and I/O

Simplify code structuring

Improve responsiveness

Seamless use of multiple CPUs

Zubair Nabi 4: Concurrency April 18, 2013 6 / 22

Page 19: Topic 4: Concurrency

Advantages

Overlap computation and I/O

Simplify code structuring

Improve responsiveness

Seamless use of multiple CPUs

Zubair Nabi 4: Concurrency April 18, 2013 6 / 22

Page 20: Topic 4: Concurrency

Critical sections

Recurring problem: Two (or more) threads trying to solve the sameproblem concurrently

Only one thread should be allowed to access the piece of code thatshould never be concurrently executed

I Known as a critical section

Only one thread should be executing within a critical sectionI Known as mutual exclusion

Zubair Nabi 4: Concurrency April 18, 2013 7 / 22

Page 21: Topic 4: Concurrency

Critical sections

Recurring problem: Two (or more) threads trying to solve the sameproblem concurrentlyOnly one thread should be allowed to access the piece of code thatshould never be concurrently executed

I Known as a critical section

Only one thread should be executing within a critical sectionI Known as mutual exclusion

Zubair Nabi 4: Concurrency April 18, 2013 7 / 22

Page 22: Topic 4: Concurrency

Critical sections

Recurring problem: Two (or more) threads trying to solve the sameproblem concurrentlyOnly one thread should be allowed to access the piece of code thatshould never be concurrently executed

I Known as a critical section

Only one thread should be executing within a critical sectionI Known as mutual exclusion

Zubair Nabi 4: Concurrency April 18, 2013 7 / 22

Page 23: Topic 4: Concurrency

Critical sections

Recurring problem: Two (or more) threads trying to solve the sameproblem concurrentlyOnly one thread should be allowed to access the piece of code thatshould never be concurrently executed

I Known as a critical section

Only one thread should be executing within a critical section

I Known as mutual exclusion

Zubair Nabi 4: Concurrency April 18, 2013 7 / 22

Page 24: Topic 4: Concurrency

Critical sections

Recurring problem: Two (or more) threads trying to solve the sameproblem concurrentlyOnly one thread should be allowed to access the piece of code thatshould never be concurrently executed

I Known as a critical section

Only one thread should be executing within a critical sectionI Known as mutual exclusion

Zubair Nabi 4: Concurrency April 18, 2013 7 / 22

Page 25: Topic 4: Concurrency

Ensuring mutex

Locks: Ability to lock and unlock a critical section (based on an atomicoperation enabled by the hardware)

I Overhead of busy waiting

Semaphores: Implemented as an integer and a queueI Ability to wait() and signal()I Can also provide condition synchronizationI Correct use requires considerable care (forgetting to call wait() orsignal())

Monitors: Explicitly declare variables and tag code as using thosevariables

I Compiler automatically declares and manages underlying primitives formutual exclusion or synchronization

I Related routines are combined together

Zubair Nabi 4: Concurrency April 18, 2013 8 / 22

Page 26: Topic 4: Concurrency

Ensuring mutex

Locks: Ability to lock and unlock a critical section (based on an atomicoperation enabled by the hardware)

I Overhead of busy waiting

Semaphores: Implemented as an integer and a queueI Ability to wait() and signal()I Can also provide condition synchronizationI Correct use requires considerable care (forgetting to call wait() orsignal())

Monitors: Explicitly declare variables and tag code as using thosevariables

I Compiler automatically declares and manages underlying primitives formutual exclusion or synchronization

I Related routines are combined together

Zubair Nabi 4: Concurrency April 18, 2013 8 / 22

Page 27: Topic 4: Concurrency

Ensuring mutex

Locks: Ability to lock and unlock a critical section (based on an atomicoperation enabled by the hardware)

I Overhead of busy waiting

Semaphores: Implemented as an integer and a queue

I Ability to wait() and signal()I Can also provide condition synchronizationI Correct use requires considerable care (forgetting to call wait() orsignal())

Monitors: Explicitly declare variables and tag code as using thosevariables

I Compiler automatically declares and manages underlying primitives formutual exclusion or synchronization

I Related routines are combined together

Zubair Nabi 4: Concurrency April 18, 2013 8 / 22

Page 28: Topic 4: Concurrency

Ensuring mutex

Locks: Ability to lock and unlock a critical section (based on an atomicoperation enabled by the hardware)

I Overhead of busy waiting

Semaphores: Implemented as an integer and a queueI Ability to wait() and signal()

I Can also provide condition synchronizationI Correct use requires considerable care (forgetting to call wait() orsignal())

Monitors: Explicitly declare variables and tag code as using thosevariables

I Compiler automatically declares and manages underlying primitives formutual exclusion or synchronization

I Related routines are combined together

Zubair Nabi 4: Concurrency April 18, 2013 8 / 22

Page 29: Topic 4: Concurrency

Ensuring mutex

Locks: Ability to lock and unlock a critical section (based on an atomicoperation enabled by the hardware)

I Overhead of busy waiting

Semaphores: Implemented as an integer and a queueI Ability to wait() and signal()I Can also provide condition synchronization

I Correct use requires considerable care (forgetting to call wait() orsignal())

Monitors: Explicitly declare variables and tag code as using thosevariables

I Compiler automatically declares and manages underlying primitives formutual exclusion or synchronization

I Related routines are combined together

Zubair Nabi 4: Concurrency April 18, 2013 8 / 22

Page 30: Topic 4: Concurrency

Ensuring mutex

Locks: Ability to lock and unlock a critical section (based on an atomicoperation enabled by the hardware)

I Overhead of busy waiting

Semaphores: Implemented as an integer and a queueI Ability to wait() and signal()I Can also provide condition synchronizationI Correct use requires considerable care (forgetting to call wait() orsignal())

Monitors: Explicitly declare variables and tag code as using thosevariables

I Compiler automatically declares and manages underlying primitives formutual exclusion or synchronization

I Related routines are combined together

Zubair Nabi 4: Concurrency April 18, 2013 8 / 22

Page 31: Topic 4: Concurrency

Ensuring mutex

Locks: Ability to lock and unlock a critical section (based on an atomicoperation enabled by the hardware)

I Overhead of busy waiting

Semaphores: Implemented as an integer and a queueI Ability to wait() and signal()I Can also provide condition synchronizationI Correct use requires considerable care (forgetting to call wait() orsignal())

Monitors: Explicitly declare variables and tag code as using thosevariables

I Compiler automatically declares and manages underlying primitives formutual exclusion or synchronization

I Related routines are combined together

Zubair Nabi 4: Concurrency April 18, 2013 8 / 22

Page 32: Topic 4: Concurrency

Ensuring mutex

Locks: Ability to lock and unlock a critical section (based on an atomicoperation enabled by the hardware)

I Overhead of busy waiting

Semaphores: Implemented as an integer and a queueI Ability to wait() and signal()I Can also provide condition synchronizationI Correct use requires considerable care (forgetting to call wait() orsignal())

Monitors: Explicitly declare variables and tag code as using thosevariables

I Compiler automatically declares and manages underlying primitives formutual exclusion or synchronization

I Related routines are combined together

Zubair Nabi 4: Concurrency April 18, 2013 8 / 22

Page 33: Topic 4: Concurrency

Ensuring mutex

Locks: Ability to lock and unlock a critical section (based on an atomicoperation enabled by the hardware)

I Overhead of busy waiting

Semaphores: Implemented as an integer and a queueI Ability to wait() and signal()I Can also provide condition synchronizationI Correct use requires considerable care (forgetting to call wait() orsignal())

Monitors: Explicitly declare variables and tag code as using thosevariables

I Compiler automatically declares and manages underlying primitives formutual exclusion or synchronization

I Related routines are combined together

Zubair Nabi 4: Concurrency April 18, 2013 8 / 22

Page 34: Topic 4: Concurrency

Outline

1 Introduction

2 Concurrency in Practice

3 Liveness

4 Message passing

5 Transactions

Zubair Nabi 4: Concurrency April 18, 2013 9 / 22

Page 35: Topic 4: Concurrency

Linux Kernel

Kernel provides spinlocks and semaphores

I Spinlocks busy wait so only hold for short time

Also provides reader-writer spinlock variantsI Allows many readers or a single writer

Zubair Nabi 4: Concurrency April 18, 2013 10 / 22

Page 36: Topic 4: Concurrency

Linux Kernel

Kernel provides spinlocks and semaphoresI Spinlocks busy wait so only hold for short time

Also provides reader-writer spinlock variantsI Allows many readers or a single writer

Zubair Nabi 4: Concurrency April 18, 2013 10 / 22

Page 37: Topic 4: Concurrency

Linux Kernel

Kernel provides spinlocks and semaphoresI Spinlocks busy wait so only hold for short time

Also provides reader-writer spinlock variants

I Allows many readers or a single writer

Zubair Nabi 4: Concurrency April 18, 2013 10 / 22

Page 38: Topic 4: Concurrency

Linux Kernel

Kernel provides spinlocks and semaphoresI Spinlocks busy wait so only hold for short time

Also provides reader-writer spinlock variantsI Allows many readers or a single writer

Zubair Nabi 4: Concurrency April 18, 2013 10 / 22

Page 39: Topic 4: Concurrency

Java

Inspired by monitors

Through the synchronize primitive

Objects already encapsulate data and methods

Block synchronization is preferred over method synchronization

C# is similar too but requires explicit invocation

Zubair Nabi 4: Concurrency April 18, 2013 11 / 22

Page 40: Topic 4: Concurrency

Java

Inspired by monitors

Through the synchronize primitive

Objects already encapsulate data and methods

Block synchronization is preferred over method synchronization

C# is similar too but requires explicit invocation

Zubair Nabi 4: Concurrency April 18, 2013 11 / 22

Page 41: Topic 4: Concurrency

Java

Inspired by monitors

Through the synchronize primitive

Objects already encapsulate data and methods

Block synchronization is preferred over method synchronization

C# is similar too but requires explicit invocation

Zubair Nabi 4: Concurrency April 18, 2013 11 / 22

Page 42: Topic 4: Concurrency

Java

Inspired by monitors

Through the synchronize primitive

Objects already encapsulate data and methods

Block synchronization is preferred over method synchronization

C# is similar too but requires explicit invocation

Zubair Nabi 4: Concurrency April 18, 2013 11 / 22

Page 43: Topic 4: Concurrency

Java

Inspired by monitors

Through the synchronize primitive

Objects already encapsulate data and methods

Block synchronization is preferred over method synchronization

C# is similar too but requires explicit invocation

Zubair Nabi 4: Concurrency April 18, 2013 11 / 22

Page 44: Topic 4: Concurrency

Outline

1 Introduction

2 Concurrency in Practice

3 Liveness

4 Message passing

5 Transactions

Zubair Nabi 4: Concurrency April 18, 2013 12 / 22

Page 45: Topic 4: Concurrency

Liveness

Want threads to make progress

To make progress need to avoid:1 Deadlock: Threads sleep waiting for each other2 Livelock: Threads execute but make no progress

For good performance also need to ensure:1 No starvation: Each thread must make progress2 Minimality: No unnecessary waiting or signalling

Zubair Nabi 4: Concurrency April 18, 2013 13 / 22

Page 46: Topic 4: Concurrency

Liveness

Want threads to make progressTo make progress need to avoid:

1 Deadlock: Threads sleep waiting for each other

2 Livelock: Threads execute but make no progress

For good performance also need to ensure:1 No starvation: Each thread must make progress2 Minimality: No unnecessary waiting or signalling

Zubair Nabi 4: Concurrency April 18, 2013 13 / 22

Page 47: Topic 4: Concurrency

Liveness

Want threads to make progressTo make progress need to avoid:

1 Deadlock: Threads sleep waiting for each other2 Livelock: Threads execute but make no progress

For good performance also need to ensure:1 No starvation: Each thread must make progress2 Minimality: No unnecessary waiting or signalling

Zubair Nabi 4: Concurrency April 18, 2013 13 / 22

Page 48: Topic 4: Concurrency

Liveness

Want threads to make progressTo make progress need to avoid:

1 Deadlock: Threads sleep waiting for each other2 Livelock: Threads execute but make no progress

For good performance also need to ensure:

1 No starvation: Each thread must make progress2 Minimality: No unnecessary waiting or signalling

Zubair Nabi 4: Concurrency April 18, 2013 13 / 22

Page 49: Topic 4: Concurrency

Liveness

Want threads to make progressTo make progress need to avoid:

1 Deadlock: Threads sleep waiting for each other2 Livelock: Threads execute but make no progress

For good performance also need to ensure:1 No starvation: Each thread must make progress

2 Minimality: No unnecessary waiting or signalling

Zubair Nabi 4: Concurrency April 18, 2013 13 / 22

Page 50: Topic 4: Concurrency

Liveness

Want threads to make progressTo make progress need to avoid:

1 Deadlock: Threads sleep waiting for each other2 Livelock: Threads execute but make no progress

For good performance also need to ensure:1 No starvation: Each thread must make progress2 Minimality: No unnecessary waiting or signalling

Zubair Nabi 4: Concurrency April 18, 2013 13 / 22

Page 51: Topic 4: Concurrency

Deadlock

Set of threads go to sleep and cannot wake up

Can only be woken by another thread who is also asleepDealing with deadlocks:

1 Ensure it never happens: Prevention and avoidance2 Let it happen but recover: Detection and recovery3 Ignore it: Let the programmer deal with it

Zubair Nabi 4: Concurrency April 18, 2013 14 / 22

Page 52: Topic 4: Concurrency

Deadlock

Set of threads go to sleep and cannot wake up

Can only be woken by another thread who is also asleep

Dealing with deadlocks:1 Ensure it never happens: Prevention and avoidance2 Let it happen but recover: Detection and recovery3 Ignore it: Let the programmer deal with it

Zubair Nabi 4: Concurrency April 18, 2013 14 / 22

Page 53: Topic 4: Concurrency

Deadlock

Set of threads go to sleep and cannot wake up

Can only be woken by another thread who is also asleepDealing with deadlocks:

1 Ensure it never happens: Prevention and avoidance

2 Let it happen but recover: Detection and recovery3 Ignore it: Let the programmer deal with it

Zubair Nabi 4: Concurrency April 18, 2013 14 / 22

Page 54: Topic 4: Concurrency

Deadlock

Set of threads go to sleep and cannot wake up

Can only be woken by another thread who is also asleepDealing with deadlocks:

1 Ensure it never happens: Prevention and avoidance2 Let it happen but recover: Detection and recovery

3 Ignore it: Let the programmer deal with it

Zubair Nabi 4: Concurrency April 18, 2013 14 / 22

Page 55: Topic 4: Concurrency

Deadlock

Set of threads go to sleep and cannot wake up

Can only be woken by another thread who is also asleepDealing with deadlocks:

1 Ensure it never happens: Prevention and avoidance2 Let it happen but recover: Detection and recovery3 Ignore it: Let the programmer deal with it

Zubair Nabi 4: Concurrency April 18, 2013 14 / 22

Page 56: Topic 4: Concurrency

Livelock

Deadlock is relatively easy to detect by humans

Livelock is less easy to detect as threads continue to run (as opposed toblocking in deadlock) but do nothing usefulPrevalent in code used to detect and handle deadlocks

I Two threads detect a deadlock and try to step aside for each other

Zubair Nabi 4: Concurrency April 18, 2013 15 / 22

Page 57: Topic 4: Concurrency

Livelock

Deadlock is relatively easy to detect by humans

Livelock is less easy to detect as threads continue to run (as opposed toblocking in deadlock) but do nothing useful

Prevalent in code used to detect and handle deadlocksI Two threads detect a deadlock and try to step aside for each other

Zubair Nabi 4: Concurrency April 18, 2013 15 / 22

Page 58: Topic 4: Concurrency

Livelock

Deadlock is relatively easy to detect by humans

Livelock is less easy to detect as threads continue to run (as opposed toblocking in deadlock) but do nothing usefulPrevalent in code used to detect and handle deadlocks

I Two threads detect a deadlock and try to step aside for each other

Zubair Nabi 4: Concurrency April 18, 2013 15 / 22

Page 59: Topic 4: Concurrency

Livelock

Deadlock is relatively easy to detect by humans

Livelock is less easy to detect as threads continue to run (as opposed toblocking in deadlock) but do nothing usefulPrevalent in code used to detect and handle deadlocks

I Two threads detect a deadlock and try to step aside for each other

Zubair Nabi 4: Concurrency April 18, 2013 15 / 22

Page 60: Topic 4: Concurrency

Outline

1 Introduction

2 Concurrency in Practice

3 Liveness

4 Message passing

5 Transactions

Zubair Nabi 4: Concurrency April 18, 2013 16 / 22

Page 61: Topic 4: Concurrency

Concurrency without shared data

Only one thread can access any particular piece of data

Different threads can own distinct chunks of data

Ensure concurrency by allowing other threads to ask for operations to bedone on their behalf (Dynamic invocation)

Can be thought of as general message passing (Similar to email)

Can be used to implement RPC

Zubair Nabi 4: Concurrency April 18, 2013 17 / 22

Page 62: Topic 4: Concurrency

Concurrency without shared data

Only one thread can access any particular piece of data

Different threads can own distinct chunks of data

Ensure concurrency by allowing other threads to ask for operations to bedone on their behalf (Dynamic invocation)

Can be thought of as general message passing (Similar to email)

Can be used to implement RPC

Zubair Nabi 4: Concurrency April 18, 2013 17 / 22

Page 63: Topic 4: Concurrency

Concurrency without shared data

Only one thread can access any particular piece of data

Different threads can own distinct chunks of data

Ensure concurrency by allowing other threads to ask for operations to bedone on their behalf (Dynamic invocation)

Can be thought of as general message passing (Similar to email)

Can be used to implement RPC

Zubair Nabi 4: Concurrency April 18, 2013 17 / 22

Page 64: Topic 4: Concurrency

Concurrency without shared data

Only one thread can access any particular piece of data

Different threads can own distinct chunks of data

Ensure concurrency by allowing other threads to ask for operations to bedone on their behalf (Dynamic invocation)

Can be thought of as general message passing (Similar to email)

Can be used to implement RPC

Zubair Nabi 4: Concurrency April 18, 2013 17 / 22

Page 65: Topic 4: Concurrency

Concurrency without shared data

Only one thread can access any particular piece of data

Different threads can own distinct chunks of data

Ensure concurrency by allowing other threads to ask for operations to bedone on their behalf (Dynamic invocation)

Can be thought of as general message passing (Similar to email)

Can be used to implement RPC

Zubair Nabi 4: Concurrency April 18, 2013 17 / 22

Page 66: Topic 4: Concurrency

Advantages

Avoids race condition

Provides a flexible APII Batching: Batch X messages togetherI Scheduling: Choose the when, who, and which of message receiptI Broadcast: Send messages to many recipients

Used as the basis for some languages, such as Linda, occam, and Erlang

Zubair Nabi 4: Concurrency April 18, 2013 18 / 22

Page 67: Topic 4: Concurrency

Advantages

Avoids race conditionProvides a flexible API

I Batching: Batch X messages togetherI Scheduling: Choose the when, who, and which of message receiptI Broadcast: Send messages to many recipients

Used as the basis for some languages, such as Linda, occam, and Erlang

Zubair Nabi 4: Concurrency April 18, 2013 18 / 22

Page 68: Topic 4: Concurrency

Advantages

Avoids race conditionProvides a flexible API

I Batching: Batch X messages together

I Scheduling: Choose the when, who, and which of message receiptI Broadcast: Send messages to many recipients

Used as the basis for some languages, such as Linda, occam, and Erlang

Zubair Nabi 4: Concurrency April 18, 2013 18 / 22

Page 69: Topic 4: Concurrency

Advantages

Avoids race conditionProvides a flexible API

I Batching: Batch X messages togetherI Scheduling: Choose the when, who, and which of message receipt

I Broadcast: Send messages to many recipients

Used as the basis for some languages, such as Linda, occam, and Erlang

Zubair Nabi 4: Concurrency April 18, 2013 18 / 22

Page 70: Topic 4: Concurrency

Advantages

Avoids race conditionProvides a flexible API

I Batching: Batch X messages togetherI Scheduling: Choose the when, who, and which of message receiptI Broadcast: Send messages to many recipients

Used as the basis for some languages, such as Linda, occam, and Erlang

Zubair Nabi 4: Concurrency April 18, 2013 18 / 22

Page 71: Topic 4: Concurrency

Advantages

Avoids race conditionProvides a flexible API

I Batching: Batch X messages togetherI Scheduling: Choose the when, who, and which of message receiptI Broadcast: Send messages to many recipients

Used as the basis for some languages, such as Linda, occam, and Erlang

Zubair Nabi 4: Concurrency April 18, 2013 18 / 22

Page 72: Topic 4: Concurrency

Erlang

Functional language from the mid 80s

Cheap, lightweight, language-level processes

Each variable is assigned only once (Immutable afterwards)

Explicit message passing via in order message delivery to local mailbox

Used to implement Facebook Chat

Zubair Nabi 4: Concurrency April 18, 2013 19 / 22

Page 73: Topic 4: Concurrency

Erlang

Functional language from the mid 80s

Cheap, lightweight, language-level processes

Each variable is assigned only once (Immutable afterwards)

Explicit message passing via in order message delivery to local mailbox

Used to implement Facebook Chat

Zubair Nabi 4: Concurrency April 18, 2013 19 / 22

Page 74: Topic 4: Concurrency

Erlang

Functional language from the mid 80s

Cheap, lightweight, language-level processes

Each variable is assigned only once (Immutable afterwards)

Explicit message passing via in order message delivery to local mailbox

Used to implement Facebook Chat

Zubair Nabi 4: Concurrency April 18, 2013 19 / 22

Page 75: Topic 4: Concurrency

Erlang

Functional language from the mid 80s

Cheap, lightweight, language-level processes

Each variable is assigned only once (Immutable afterwards)

Explicit message passing via in order message delivery to local mailbox

Used to implement Facebook Chat

Zubair Nabi 4: Concurrency April 18, 2013 19 / 22

Page 76: Topic 4: Concurrency

Erlang

Functional language from the mid 80s

Cheap, lightweight, language-level processes

Each variable is assigned only once (Immutable afterwards)

Explicit message passing via in order message delivery to local mailbox

Used to implement Facebook Chat

Zubair Nabi 4: Concurrency April 18, 2013 19 / 22

Page 77: Topic 4: Concurrency

Outline

1 Introduction

2 Concurrency in Practice

3 Liveness

4 Message passing

5 Transactions

Zubair Nabi 4: Concurrency April 18, 2013 20 / 22

Page 78: Topic 4: Concurrency

Transactions

Either executes correctly (commits) or has no effect at all

Properties:1 Atomicity: Either all or none of the operations are performed2 Consistency: A transaction transforms the system from one consistent

state to another3 Isolation: Each transaction gives the notion of sandboxing from the

concurrent effects of others4 Durability: The effects of committed transactions survive subsequent

system failures

Zubair Nabi 4: Concurrency April 18, 2013 21 / 22

Page 79: Topic 4: Concurrency

Transactions

Either executes correctly (commits) or has no effect at allProperties:

1 Atomicity: Either all or none of the operations are performed

2 Consistency: A transaction transforms the system from one consistentstate to another

3 Isolation: Each transaction gives the notion of sandboxing from theconcurrent effects of others

4 Durability: The effects of committed transactions survive subsequentsystem failures

Zubair Nabi 4: Concurrency April 18, 2013 21 / 22

Page 80: Topic 4: Concurrency

Transactions

Either executes correctly (commits) or has no effect at allProperties:

1 Atomicity: Either all or none of the operations are performed2 Consistency: A transaction transforms the system from one consistent

state to another

3 Isolation: Each transaction gives the notion of sandboxing from theconcurrent effects of others

4 Durability: The effects of committed transactions survive subsequentsystem failures

Zubair Nabi 4: Concurrency April 18, 2013 21 / 22

Page 81: Topic 4: Concurrency

Transactions

Either executes correctly (commits) or has no effect at allProperties:

1 Atomicity: Either all or none of the operations are performed2 Consistency: A transaction transforms the system from one consistent

state to another3 Isolation: Each transaction gives the notion of sandboxing from the

concurrent effects of others

4 Durability: The effects of committed transactions survive subsequentsystem failures

Zubair Nabi 4: Concurrency April 18, 2013 21 / 22

Page 82: Topic 4: Concurrency

Transactions

Either executes correctly (commits) or has no effect at allProperties:

1 Atomicity: Either all or none of the operations are performed2 Consistency: A transaction transforms the system from one consistent

state to another3 Isolation: Each transaction gives the notion of sandboxing from the

concurrent effects of others4 Durability: The effects of committed transactions survive subsequent

system failures

Zubair Nabi 4: Concurrency April 18, 2013 21 / 22

Page 83: Topic 4: Concurrency

References

Operating systems: Concurrent and distributed software design. JeanBacon and Tim Harris, Addison Wesley, 2003

Zubair Nabi 4: Concurrency April 18, 2013 22 / 22