Concurrency: how to shoot yourself in both feet. Simultaneously.

35
Concurrency How to shoot yourself in both feet. Simultaneously. Victor Haydin R&D Manager @ ELEKS

Transcript of Concurrency: how to shoot yourself in both feet. Simultaneously.

Page 1: Concurrency: how to shoot yourself in both feet. Simultaneously.

Concurrency

How to shoot yourself in both feet.Simultaneously.

Victor HaydinR&D Manager @ ELEKS

Page 2: Concurrency: how to shoot yourself in both feet. Simultaneously.

The Problem

Page 3: Concurrency: how to shoot yourself in both feet. Simultaneously.

Multithreading?Parallelism?

Concurrency?

Page 4: Concurrency: how to shoot yourself in both feet. Simultaneously.
Page 5: Concurrency: how to shoot yourself in both feet. Simultaneously.

Single threaded programming

Page 6: Concurrency: how to shoot yourself in both feet. Simultaneously.

Concurrent programming*

* as you imagine it

Page 7: Concurrency: how to shoot yourself in both feet. Simultaneously.

Concurrent programm

ing** in real world

Page 8: Concurrency: how to shoot yourself in both feet. Simultaneously.
Page 9: Concurrency: how to shoot yourself in both feet. Simultaneously.

Shared state

Page 10: Concurrency: how to shoot yourself in both feet. Simultaneously.

Traditional way

Page 11: Concurrency: how to shoot yourself in both feet. Simultaneously.
Page 12: Concurrency: how to shoot yourself in both feet. Simultaneously.
Page 13: Concurrency: how to shoot yourself in both feet. Simultaneously.

WTF?!

Page 14: Concurrency: how to shoot yourself in both feet. Simultaneously.

Web 2.0 – 2003First dual-core CPU – 2005Cloud Computing - 2006

Page 15: Concurrency: how to shoot yourself in both feet. Simultaneously.

C++ - 1983Java - 1995C# - 2001

Page 16: Concurrency: how to shoot yourself in both feet. Simultaneously.

Alternate ways

Page 17: Concurrency: how to shoot yourself in both feet. Simultaneously.

Transactional memoryFunctional programming

Messaging

Page 18: Concurrency: how to shoot yourself in both feet. Simultaneously.
Page 19: Concurrency: how to shoot yourself in both feet. Simultaneously.

atomic {if (from.Ballance < amount)

throw new InsufficientBalanceException("Not enough money"); from.Debit(amount); to.Credit(amount);}

Page 20: Concurrency: how to shoot yourself in both feet. Simultaneously.

Atomic.Do(() => {if (from.Ballance < amount)

throw new InsufficientBalanceException("Not enough money"); from.Debit(amount); to.Credit(amount);});

Page 21: Concurrency: how to shoot yourself in both feet. Simultaneously.

STM HTM

Page 22: Concurrency: how to shoot yourself in both feet. Simultaneously.
Page 23: Concurrency: how to shoot yourself in both feet. Simultaneously.

Immutable data means no side effects. No side effects – no

concurrency problems!*

* except if you need I/O

Page 24: Concurrency: how to shoot yourself in both feet. Simultaneously.

Wait a second, what about I/O?

Page 25: Concurrency: how to shoot yourself in both feet. Simultaneously.
Page 26: Concurrency: how to shoot yourself in both feet. Simultaneously.

FP != easy concurrencyFP == easy parallelism

Page 27: Concurrency: how to shoot yourself in both feet. Simultaneously.
Page 28: Concurrency: how to shoot yourself in both feet. Simultaneously.
Page 29: Concurrency: how to shoot yourself in both feet. Simultaneously.
Page 30: Concurrency: how to shoot yourself in both feet. Simultaneously.
Page 31: Concurrency: how to shoot yourself in both feet. Simultaneously.
Page 32: Concurrency: how to shoot yourself in both feet. Simultaneously.

NActStact

Retlang

Page 33: Concurrency: how to shoot yourself in both feet. Simultaneously.
Page 34: Concurrency: how to shoot yourself in both feet. Simultaneously.

…or use single thread.

Page 35: Concurrency: how to shoot yourself in both feet. Simultaneously.

Q&A