Presentation is loading. Please wait.

Presentation is loading. Please wait.

Better concurrency with a.NET language for isolation and asynchrony 1.

Similar presentations

Presentation on theme: "Better concurrency with a.NET language for isolation and asynchrony 1."— Presentation transcript:

1 Better concurrency with a.NET language for isolation and asynchrony 1

2 Axum == Maestro “What's in a name? That which we call a rose By any other name would smell as sweet." Shakespeare, Romeo and Juliet (II, ii, 1-2) 2

3 Incubation Project Farther along than research But not yet in productization phase Have released internally in Microsoft Will soon release a public beta 3

4 Inspirational Quotes “If the state of your entire universe can change from one instant to the next, there’s something wrong with your universe.” “Programmers are asked to take a wildly non-deterministic model and rein it in where needed. We should start with a deterministic model and add non-determinism where necessary.” Ed Lee, UCB 4

5 Axum Language Imperative, managed language Looks and feels like C# or C++ Has curly-brace! And a few other familiar concepts … Works with all.Net libraries Such as BCL Can be mixed with C# or VB.Net Even in the same project! Built on top of CCR 5

6 Why Another Language? Relying on programmer’s discipline doesn’t work Library solutions can only do so much We want strong safety enforced by the compiler Reduce complexity Concurrent by default “Forget” you’re writing a parallel program Not intended to substitute other languages High level orchestration in Axum Most of the application still written in traditional language 6

7 Isolation Shared state is evil Processes in OS Tabs and plug-ins in Google Chrome Computers on the Web But: worms, viruses and trojans (when isolation breaks down) 7

8 Main Concepts Domains Passive containers of state Agents Active components; can send messages and share state within the same domain Channels and Ports “Pipes” that conduct messages A channel has a collection of ports 8

9 Example: Tax Calculator public channel TaxCalculator { input int Income; output int Tax; } public agent TaxAgent : channel TaxCalculator { public TaxAgent() { var income = receive(this.PrimaryChannel::Income); var tax = (int)(income * GetTaxRate()); this.PrimaryChannel::Tax <-- tax; } 9

10 Example: Tax Calculator, 2 TaxService.TaxCalculator taxCalculator = new TaxService.TaxCalculator("TaxCalc1"); taxCalculator::Income <-- 50000; // Do something useful while the // taxes are being calculated... int taxAmount = receive(taxCalculator::Tax); 10

11 TaxCalculator Agents and Channels 11 User AgentServer Agent Income Tax

12 Example: Tax Calculator, 3 Demo: Simple Input/Output ports Request-Reply port Forwarding network 12

13 Dataflow Programming Execution is triggered by the availability of data Spreadsheet: Change in a cell triggers reevaluation of dependent cells; Independent cells can change concurrently Compiler: Characters flow through lexer turning into tokens; Tokens go through grammar turning into AST; AST goes through several passes 13

14 Image Processor ReadSharpenRed EyeShrinkSave 14 Read JPG, Sharpen, Reduce “red eye” effect, Shrink, Save as 85% quality JPG Simple pipeline PrimaryChannel::FileName ==> Sharpen ==> RemoveRedEye ==> Shrink ==> Save; Contrast with: Save(Shrink(RemoveRedEye(Sharpen(filename))));

15 Isolation No two stages of the pipeline can access the same image! Let’s dive deeper… 15

16 Units Of Isolation in Axum Domains Passive containers of shared state Agents Disciplined access to domain state Writer: can write domain state Reader: can read domain state No-access: cannot access domain mutable state True Functions In agents, cannot modify domain and agent state In domains, cannot modify domain state 16

17 Example domain D { int data; reader agent A : channel C { public A() { int n = data; // OK data = 10; // error! } function void f() { data = 20; // error } 17

18 Example, cont domain D { int data; const int cdata; agent A : channel C // no-access agent { public A() { int n = data; // error int m = cdata; // OK } 18

19 Good ‘ol C++ Const data: const int n=1; Pointer to const: int const * p = &n; Rule 1: Cannot modify const data const S* ps; *ps = s; // error (*ps).val = 0;// error ps->val = 10; // ditto Rule 2: Cannot convert pointer to const to pointer to non-const 19

20 The Many Faces of Const struct S { int val; void f() const { val = 1; // Error! // Translates to: // (*this).val = 1; } }; 20

21 Loophole! struct S { int val; int *ptr; }; … const S * ps = &s; // error: l-value specifies const object: ps->val = 0; *ps->ptr = 1; // OK! 21

22 Example domain D { int data; reader agent A : channel C { public A() { int n =; // OK, parent is readonly = 10; // error! } function void f() { = 20; // error, this is readonly } 22

23 Immutability in Axum Readonly vs. Const Data cannot be mutated through readonly reference. Const reference can only refer to immutable data (data that never changes) Readonly: “I won’t break you” Const: “You won’t break me” Deep immutability a.b.c.d = 1; // error if one of a,b,c,d is readonly 23

24 Concurrency in Network Same model: one writer or multiple readers Execution scheduled in the most efficient safe way 24 Domain Reader Agent1 method1 method2 function1 function2 m1 m2 f1 f2 Writer Agent2 m1 m2 f1 f2 No Access Agent3 m1 m2 f1 f2

25 No Silver Bullet… Non-determinism Deadlocks Demo: Dining Philosophers 25

26 Thank you! We need your feedback! Check out our blog: 26

Download ppt "Better concurrency with a.NET language for isolation and asynchrony 1."

Similar presentations

Ads by Google