racing to win: using race conditions to build correct and concurrent software

187
Racing To Win Using Race Conditions to Build Correct & Concurrent Software Nathan Taylor | nathan.dijkstracula.net | @dijkstracula

Upload: fastly

Post on 16-Apr-2017

1.026 views

Category:

Internet


0 download

TRANSCRIPT

Page 1: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

Racing To WinUsing Race Conditions to Build

Correct & Concurrent Software

Nathan Taylor | nathan.dijkstracula.net | @dijkstracula

Page 2: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

Racing To WinUsing Race Conditions to Build

Correct & Concurrent Software

Nathan Taylor | nathan.dijkstracula.net | @dijkstracula

Page 3: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

Hi, I’m Nathan. ( @dijkstracula )

Page 4: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

I’m an engineer at

Page 5: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software
Page 6: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

A problem

Page 7: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

A problem

A solution

Page 8: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

A problem

A solution

Page 9: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software
Page 10: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software
Page 11: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software
Page 12: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software
Page 13: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

Cache node

Page 14: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

Cache node

Process A

stack

heap

text

Process B

stack

heap

text

Process C

stack

heap

text

Page 15: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

Cache node

Process A

stack

heap

text

Process B

stack

heap

text

Process C

stack

heap

text

Page 16: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

A Persistent, Shared-State Memory Allocator

Cache node

Process A

stack

heap

text

Process B

stack

heap

text

Process C

stack

heap

text

uSlab

Page 17: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

Slab allocation

Page 18: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

Slab allocationObject Object Object Object Object Object Object Object

Page 19: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

Object Object Object Object Object Object Object Object

Page 20: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

s_alloc();

s_alloc();Object

Object

Object

Object Object Object Object Object

s_alloc();

Page 21: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

Object

Object

Object

Object Object Object Object Object

Page 22: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

Object

Object

Object

Object Object Object Object Object

Page 23: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

s_free(              );

s_free(              );

s_free(              );

Object ObjectObject Object Object Object Object Object

Page 24: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

Object Object Object Object Object Object Object Object

Page 25: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

Object Object Object Object Object Object Object Object

Page 26: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

Allocation Protocol• An request to allocate is followed by a response

containing an object

• A request to free is followed by a response after the supplied object has been released

• Allocation requests must not respond with an already-allocated object

• A free request must not release an already-unallocated object

Page 27: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

An Execution History

Page 28: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

An Execution Historyvoid foo() { obj *a = s_alloc(); s_free(a); … }

Page 29: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

An Execution History

Time

void foo() { obj *a = s_alloc(); s_free(a); … }

A(allocate request) B(allocate response) A(free request) B(free response)

Page 30: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

An Execution History

Time

A(allocate request)

B(allocate request)

A(allocate response)

B(allocate response)

Page 31: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

An Execution History

Time

A(allocate request)

B(allocate request)

A(allocate response)

B(allocate response)

“X happened before Y” => “Y may observe X to have occurred”

Page 32: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

A(allocate response)

A(allocate request)

B(allocate request)

B(allocate response)Time

Page 33: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

A(allocate response)

A(allocate request)

B(allocate request)

B(allocate response)

Time

Page 34: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

A(allocate response)

A(allocate request)

B(allocate request)

B(allocate response)

A protocol violation!

Time

Page 35: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

Time A(allocate response)

A(allocate request)

B(allocate request)

B(allocate response)

Page 36: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

Time A(allocate response)

A(allocate request)

B(allocate request)

B(allocate response)

Page 37: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

http://cs.brown.edu/~mph/HerlihyW90/p463-herlihy.pdf

Page 38: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

A Sequential History

Time

Page 39: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

A Sequential History

Time

A(allocate request)

A(allocate response)

A(free request)

A(free response)

B(allocate request)

B(allocate response)

Page 40: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

A Sequential History

Time

A(allocate request)

A(allocate response){ }

A(free request)

A(free response){ }

B(allocate request)

B(allocate response){ }

Page 41: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

A Sequential History

Time

A(allocate request)

A(allocate response){ }

A(free request)

A(free response){ }

B(allocate request)

B(allocate response){ }

Page 42: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

A Sequential History

Time

A(allocate request)

A(allocate response){ }A(free request)

A(free response){ }B(allocate request)

B(allocate response){ }

Page 43: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

obj  *allocate(slab  *s)  {    obj  *a  =  s-­‐>head;    if  (a  ==  NULL)  return  NULL;    s-­‐>head  =  a-­‐>next;    return  a;}  

void  free(slab  *s,  obj  *o)  {

   o-­‐>next  =  s-­‐>head;    s-­‐>head  =  o;

}

Page 44: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

obj  *allocate(slab  *s)  {    lock(&allocator_lock);    obj  *a  =  s-­‐>head;    if  (a  ==  NULL)  return  NULL;    s-­‐>head  =  a-­‐>next;    unlock(&allocator_lock);    return  a;}  

void  free(slab  *s,  obj  *o)  {    lock(&allocator_lock);      o-­‐>next  =  s-­‐>head;    s-­‐>head  =  o;    unlock(&allocator_lock);  }

Page 45: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

Was the State Locked?

Yes

Done

No

Atom

ic

Page 46: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

Fetch Old Lock State

Set State Locked

Was old State Locked?

Yes

Done

No

Atom

ic

Page 47: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

Fetch Old Lock State

Set State Locked

Was old State Locked?

Yes

Done

No

Atom

ic

Test And Set Lock

Page 48: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

Test And Set Unlock

Set State Unlocked

Atom

ic

Page 49: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

typedef  spinlock  int;#define  LOCKED  1#define  UNLOCKED  0void  lock(spinlock  *m)  {    while  (atomic_tas(m,  LOCKED)  ==  LOCKED)          snooze();}  

void  unlock(spinlock  *m)  {    atomic_store(m,  UNLOCKED);} Many code examples

derived from Concurrency Kit http://concurrencykit.org

Page 50: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

void  lock(spinlock  *m)  {    while  (atomic_tas(m,  LOCKED)  ==  LOCKED)          snooze();}

A(TAS request)

A(TAS response){ }

Page 51: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

A(TAS request)

A(TAS response){ }

TAS is embedded in Lock

Page 52: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

A(TAS request)

A(TAS response){ }A(lock request)

A(lock response)

Time

TAS is embedded in Lock

Page 53: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

A(TAS request)

A(TAS response){ }A(lock request)

A(lock response)

Time

TAS & Store can’t be reordered

Page 54: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

A(TAS request)

A(TAS response){ }A(lock request)

A(lock response)

Time

B(unlock request)

B(unlock response)

B(Store request)

B(Store response){ }

TAS & Store can’t be reordered

Page 55: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software
Page 56: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

All execution histories

All sequentially-consistent execution histories

Page 57: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

All execution histories

All sequentially-consistent execution histories

All ???able execution histories

Page 58: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

All execution histories

All sequentially-consistent execution histories

All linearizable execution histories

Page 59: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

A(TAS request)

A(TAS response){ }A(lock request)

A(lock response)

Time

Others can be reordered

B(unlock request)

B(unlock response)

B(Store request)

B(Store response){ }

Page 60: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

A(TAS request)

A(TAS response){ }A(lock request)

A(lock response)

Time

Others can be reordered

B(unlock request)

B(unlock response)

B(Store request)

B(Store response){ }

Page 61: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

void  lock(spinlock  *m)  {    while  (atomic_tas(m,  LOCKED)  ==  LOCKED)          snooze();}  

void  unlock(spinlock  *m)  {    atomic_store(m,  UNLOCKED);}

Page 62: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

http://dl.acm.org/citation.cfm?id=69624.357207

Page 63: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

obj  *allocate(slab  *s)  {    lock(&allocator_lock);    obj  *a  =  s-­‐>head;    if  (a  ==  NULL)  return  NULL;    s-­‐>head  =  a-­‐>next;    unlock(&allocator_lock);    return  a;}  

void  free(slab  *s,  obj  *o)  {    lock(&allocator_lock);      o-­‐>next  =  s-­‐>head;    s-­‐>head  =  o;    unlock(&allocator_lock);  }

Page 64: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

void  lock(spinlock  *m)  {    while  (atomic_tas(m,  LOCKED)  ==  LOCKED)          snooze();}  

void  unlock(spinlock  *m)  {    atomic_store(m,  UNLOCKED);}

Page 65: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

Spinlock performance m

illio

ns o

f loc

k ac

quis

ition

s / s

ec

15

30

45

60

75

90

Threads

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

87.351Test and Set

Page 66: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

Spinlock performance m

illio

ns o

f loc

k ac

quis

ition

s / s

ec

15

30

45

60

75

90

Threads

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

Platonic ideal of a spinlock

Page 67: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

Spinlock performance m

illio

ns o

f loc

k ac

quis

ition

s / s

ec

15

30

45

60

75

90

Threads

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

87.351

4.343

Test and Set

Page 68: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

Spinlock performance m

illio

ns o

f loc

k ac

quis

ition

s / s

ec

15

30

45

60

75

90

Threads

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

Test and Set

Page 69: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

Spinlock performance a

cqui

sitio

ns /

sec

1E+011E+021E+031E+041E+051E+061E+071E+08

Threads

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

Test and Set

Page 70: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

typedef  spinlock  int;#define  LOCKED  1#define  UNLOCKED  0void  lock(spinlock  *m)  {    while  (atomic_tas(m,  LOCKED)  ==  LOCKED)          snooze();}  

Page 71: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

typedef  spinlock  int;#define  LOCKED  1#define  UNLOCKED  0void  lock(spinlock  *m)  {    while  (atomic_tas(m,  LOCKED)  ==  LOCKED)  {        while  (atomic_store(m)  ==  LOCKED)              snooze();    }}  

Page 72: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

typedef  spinlock  int;#define  LOCKED  1#define  UNLOCKED  0void  lock(spinlock  *m)  {    while  (atomic_tas(m,  LOCKED)  ==  LOCKED)  {        while  (atomic_store(m)  ==  LOCKED)              snooze();    }}  

Test-and-Test-and-Set

Page 73: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

Lock

ed a

lloc/

free

(10s

)

10100

1,00010,000

100,0001,000,000

10,000,000100,000,000

Threads

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

Test and Set T&T&S

Page 74: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

Spinlock performanceLo

cked

allo

c/fre

e (1

0s)

10100

1,00010,000

100,0001,000,000

10,000,000100,000,000

Threads

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

Test and Set T&T&S

Page 75: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

typedef  spinlock  int;#define  LOCKED  1#define  UNLOCKED  0void  lock(spinlock  *m)  {      unsigned  long  backoff,  exp  =  0;      while  (atomic_tas(m,  LOCKED)  ==  LOCKED)  {          for  (i  =  0;  i  <  backoff;  i++)              snooze();          backoff  =  (1ULL  <<  exp++);      }}  

Page 76: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

typedef  spinlock  int;#define  LOCKED  1#define  UNLOCKED  0void  lock(spinlock  *m)  {      unsigned  long  backoff,  exp  =  0;      while  (atomic_tas(m,  LOCKED)  ==  LOCKED)  {          for  (i  =  0;  i  <  backoff;  i++)              snooze();          backoff  =  (1ULL  <<  exp++);      }}  

TAS + backoff

Page 77: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

Lock

ed a

lloc/

free

(10s

)

10,000,000

20,000,000

30,000,000

40,000,000

50,000,000

60,000,000

Threads

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

Test and Set T&T&S TAS + EB

Page 78: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

void  lock(spinlock  *m)  {    while  (atomic_tas(m,  LOCKED)  ==  LOCKED)          snooze();}

void  lock(spinlock  *m)  {    while  (atomic_tas(m,  LOCKED)  ==  LOCKED)          snooze();}

spinlock  global_lock  = UNLOCKED

Page 79: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

void  lock(spinlock  *m)  {    while  (atomic_tas(m,  LOCKED)  ==  LOCKED)          snooze();}

void  lock(spinlock  *m)  {    while  (atomic_tas(m,  LOCKED)  ==  LOCKED)          snooze();}

spinlock  global_lock  = UNLOCKED

Page 80: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

void  lock(spinlock  *m)  {    while  (atomic_tas(m,  LOCKED)  ==  LOCKED)          snooze();}

void  lock(spinlock  *m)  {    while  (atomic_tas(m,  LOCKED)  ==  LOCKED)          snooze();}

spinlock  global_lock  = UNLOCKED

Page 81: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

void  lock(spinlock  *m)  {    while  (atomic_tas(m,  LOCKED)  ==  LOCKED)          snooze();}

void  lock(spinlock  *m)  {    while  (atomic_tas(m,  LOCKED)  ==  LOCKED)          snooze();}

spinlock  global_lock  = UNLOCKED

Page 82: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

void  lock(spinlock  *m)  {    while  (atomic_tas(m,  LOCKED)  ==  LOCKED)          snooze();}

void  lock(spinlock  *m)  {    while  (atomic_tas(m,  LOCKED)  ==  LOCKED)          snooze();}

spinlock  global_lock  = LOCKED

Page 83: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

void  lock(spinlock  *m)  {    while  (atomic_tas(m,  LOCKED)  ==  LOCKED)          snooze();}

void  lock(spinlock  *m)  {    while  (atomic_tas(m,  LOCKED)  ==  LOCKED)          snooze();}

spinlock  global_lock  = LOCKED

Page 84: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

void  lock(spinlock  *m)  {    while  (atomic_tas(m,  LOCKED)  ==  LOCKED)          snooze();}

void  lock(spinlock  *m)  {    while  (atomic_tas(m,  LOCKED)  ==  LOCKED)          snooze();}

spinlock  global_lock  = LOCKED

Page 85: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

void  lock(spinlock  *m)  {    while  (atomic_tas(m,  LOCKED)  ==  LOCKED)          snooze();}

void  lock(spinlock  *m)  {    while  (atomic_tas(m,  LOCKED)  ==  LOCKED)          snooze();}

spinlock  global_lock  = LOCKED

Page 86: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

void  lock(spinlock  *m)  {    while  (atomic_tas(m,  LOCKED)  ==  LOCKED)          snooze();}

void  lock(spinlock  *m)  {    while  (atomic_tas(m,  LOCKED)  ==  LOCKED)          snooze();}

spinlock  global_lock  = LOCKED

Page 87: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

void  lock(spinlock  *m)  {    while  (atomic_tas(m,  LOCKED)  ==  LOCKED)          snooze();}

void  lock(spinlock  *m)  {    while  (atomic_tas(m,  LOCKED)  ==  LOCKED)          snooze();}

spinlock  global_lock  = LOCKED

Page 88: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

A function is lock-free if at all times at least one thread is

guaranteed to be making progress [in the function].

(Herlihy & Shavit)

Page 89: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software
Page 90: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

//  TODO:  make  this  safe  and  scalableobj  *allocate(slab  *s)  {    obj  *a  =  s-­‐>head;    if  (a  ==  NULL)  return  NULL;    s-­‐>head  =  a-­‐>next;    return  a;}  

//  TODO:  make  this  safe  and  scalable  void  free(slab  *s,  obj  *o)  {      o-­‐>next  =  s-­‐>head;    s-­‐>head  =  o;  }

Page 91: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

Non-Blocking Algorithms

Page 92: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

Compare-And-Swap

Page 93: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

Compare-And-Swap

Cmpr and *

Old value Destination Address

Page 94: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

Compare-And-Swap

Return false

Old value Destination Address

Cmpr and *

Page 95: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

Compare-And-SwapOld value New value

Return false

=

Destination Address

Copy to *

Return true

Cmpr and *

Page 96: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

Compare-And-SwapOld value New value

Return false

=

Destination Address

Return true

Atomic

Copy to * Cmpr and *

Page 97: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

Atomic i  =  i+1;

void  atomic_inc(int  *ptr)  {    int  i,  i_plus_one;    do  {          i  =  *ptr;          i_plus_one  =  i  +  1;    }  while  (!cas(i,  i_plus_one,  ptr));  }

Page 98: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

void  atomic_inc(int  *ptr)  {    int  i,  i_plus_one;    do  {          i  =  *ptr;          i_plus_one  =  i  +  1;    }  while  (!cas(i,  i_plus_one,  ptr));  }

Atomic i  =  i+1;

Page 99: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

void  atomic_inc(int  *ptr)  {    int  i,  i_plus_one;    do  {          i  =  *ptr;          i_plus_one  =  i  +  1;    }  while  (!cas(i,  i_plus_one,  ptr));  }

Atomic i  =  i+1;

Page 100: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

void  atomic_inc(int  *ptr)  {    int  i,  i_plus_one;    do  {          i  =  *ptr;          i_plus_one  =  i  +  1;    }  while  (!cas(i,  i_plus_one,  ptr));  }

Atomic i  =  i+1;

Page 101: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

void  atomic_inc_mod_32(int  *ptr)  {    int  i,  new_i;    do  {          i  =  *ptr;          new_i  =  i  +  1;          new_i  =  new_i  %  32;    }  while  (!cas(i,  new_i,  ptr));}

Atomic i  =  (i+1)  %  32;

Page 102: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

TAS using CAS

void  tas_loop(spinlock  *m)  {    do  {          ;    }  while  (!cas(UNLOCKED,  LOCKED,  m));  }

Page 103: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

Read/Modify/Write

void  atomic_inc_mod_32(int  *ptr)  {    int  i,  new_i;    do  {          i  =  *ptr;                                          /*  Read  */          new_i  =  fancy_function();      /*  Modify  */    }  while  (!cas(i,  new_i,  ptr));  /*  Write  */                                                    }

Page 104: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

Read/Modify/Write

void  atomic_inc_mod_32(int  *ptr)  {    int  i,  new_i;    do  {          i  =  *ptr;                                          /*  Read  */          new_i  =  fancy_function();      /*  Modify  */    }  while  (!cas(i,  new_i,  ptr));  /*  Write  */                                                          /*  (or  retry)  */}

Page 105: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

obj  *allocate(slab  *s)  {    obj  *a,  *b;    do  {        a  =  s-­‐>head;        if  (a  ==  NULL)  return  NULL;        b  =  a-­‐>next;    }  while  (!cas(a,  b,  &s-­‐>head  ));    return  a;}

slab head A B …

Page 106: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

obj  *allocate(slab  *s)  {    obj  *a,  *b;    do  {        a  =  s-­‐>head;        if  (a  ==  NULL)  return  NULL;        b  =  a-­‐>next;    }  while  (!cas(a,  b,  &s-­‐>head  ));    return  a;}

slab head A B …

Page 107: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

obj  *allocate(slab  *s)  {    obj  *a,  *b;    do  {        a  =  s-­‐>head;        if  (a  ==  NULL)  return  NULL;        b  =  a-­‐>next;    }  while  (!cas(a,  b,  &s-­‐>head  ));    return  a;}

A B …slab head

Page 108: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

B …slab head

A

obj  *allocate(slab  *s)  {    obj  *a,  *b;    do  {        a  =  s-­‐>head;        if  (a  ==  NULL)  return  NULL;        b  =  a-­‐>next;    }  while  (!cas(a,  b,  &s-­‐>head  ));    return  a;}

Page 109: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

obj  *allocate(slab  *s)  {    obj  *a,  *b;    do  {        a  =  s-­‐>head;        if  (a  ==  NULL)  return  NULL;        b  =  a-­‐>next;    }  while  (!cas(    ,    ,                  ));    return    a;}

slab head

a

a b

Cmpr and *

&s->head

A B …

b

a

Page 110: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

slab head

Cmpr and

Z

obj  *allocate(slab  *s)  {    obj  *a,  *b;    do  {        a  =  s-­‐>head;        if  (a  ==  NULL)  return  NULL;        b  =  a-­‐>next;    }  while  (!cas(    ,    ,                  ));    return    a;}

a

a b &s->headb

a

Page 111: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

slab head Z A B

Cmpr and

obj  *allocate(slab  *s)  {    obj  *a,  *b;    do  {        a  =  s-­‐>head;        if  (a  ==  NULL)  return  NULL;        b  =  a-­‐>next;    }  while  (!cas(    ,    ,                  ));    return    a;}

a

a b &s->headb

a

Page 112: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

slab head B …

Cmpr and

obj  *allocate(slab  *s)  {    obj  *a,  *b;    do  {        a  =  s-­‐>head;        if  (a  ==  NULL)  return  NULL;        b  =  a-­‐>next;    }  while  (!cas(    ,    ,                  ));    return    a;}

a

a b &s->headb

a

Page 113: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

void  free(slab  *s,  obj  *o)  {          do  {                  obj  *t  =  s-­‐>head;                  o-­‐>next  =  t;          }  while  (!cas(t,  o,  &s-­‐>head));  }

B …slab head

Page 114: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

void  free(slab  *s,  obj  *o)  {          do  {                  obj  *t  =  s-­‐>head;                  o-­‐>next  =  t;          }  while  (!cas(t,  o,  &s-­‐>head));  }

slab head A B …

Page 115: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

A B Cslab head

Page 116: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

A B Cslab head

Page 117: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

obj  *allocate(slab  *s)  {    obj  *a,  *b;    do  {        a  =  s-­‐>head;        if  (a  ==  NULL)  return  NULL;        b  =  a-­‐>next;    }  while  (!cas(a,  b,  &s-­‐>head));    return  a;}

A B Cslab head

Page 118: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

obj  *allocate(slab  *s)  {    obj  *a,  *b;    do  {        a  =  s-­‐>head;        if  (a  ==  NULL)  return  NULL;        b  =  a-­‐>next;    }  while  (!cas(a,  b,  &s-­‐>head));    return  a;}

A B Cslab head

Page 119: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

A B C

obj  *allocate(slab  *s)  {    obj  *a,  *b;    do  {        a  =  s-­‐>head;        if  (a  ==  NULL)  return  NULL;        b  =  a-­‐>next;    }  while  (!cas(a,  b,  &s-­‐>head));    return  a;}

slab head

Page 120: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

A B C

obj  *allocate(slab  *s)  {    obj  *a,  *b;    do  {        a  =  s-­‐>head;        if  (a  ==  NULL)  return  NULL;        b  =  a-­‐>next;    }  while  (!cas(a,  b,  &s-­‐>head));    return  a;}

slab head

Page 121: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

A B C

some_object  =  allocate(&shared_slab);

slab head

obj  *allocate(slab  *s)  {    obj  *a,  *b;    do  {        a  =  s-­‐>head;        if  (a  ==  NULL)  return  NULL;        b  =  a-­‐>next;    }  while  (!cas(a,  b,  &s-­‐>head));    return  a;}

Page 122: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

A B C

some_object  =  allocate(&shared_slab);

slab head

obj  *allocate(slab  *s)  {    obj  *a,  *b;    do  {        a  =  s-­‐>head;        if  (a  ==  NULL)  return  NULL;        b  =  a-­‐>next;    }  while  (!cas(a,  b,  &s-­‐>head));    return  a;}

Page 123: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

B C

A

slab head

some_object  =  allocate(&shared_slab);

obj  *allocate(slab  *s)  {    obj  *a,  *b;    do  {        a  =  s-­‐>head;        if  (a  ==  NULL)  return  NULL;        b  =  a-­‐>next;    }  while  (!cas(a,  b,  &s-­‐>head));    return  a;}

Page 124: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

B C

A

slab head

some_object  =  allocate(&shared_slab);

obj  *allocate(slab  *s)  {    obj  *a,  *b;    do  {        a  =  s-­‐>head;        if  (a  ==  NULL)  return  NULL;        b  =  a-­‐>next;    }  while  (!cas(a,  b,  &s-­‐>head));    return  a;}

Page 125: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

B C

another_obj  =  allocate(&shared_slab);

A

slab head

some_object  =  allocate(&shared_slab);

obj  *allocate(slab  *s)  {    obj  *a,  *b;    do  {        a  =  s-­‐>head;        if  (a  ==  NULL)  return  NULL;        b  =  a-­‐>next;    }  while  (!cas(a,  b,  &s-­‐>head));    return  a;}

Page 126: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

B C

another_obj  =  allocate(&shared_slab);

A

slab head

some_object  =  allocate(&shared_slab);

obj  *allocate(slab  *s)  {    obj  *a,  *b;    do  {        a  =  s-­‐>head;        if  (a  ==  NULL)  return  NULL;        b  =  a-­‐>next;    }  while  (!cas(a,  b,  &s-­‐>head));    return  a;}

Page 127: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

C

A

B

slab head

another_obj  =  allocate(&shared_slab);

some_object  =  allocate(&shared_slab);

obj  *allocate(slab  *s)  {    obj  *a,  *b;    do  {        a  =  s-­‐>head;        if  (a  ==  NULL)  return  NULL;        b  =  a-­‐>next;    }  while  (!cas(a,  b,  &s-­‐>head));    return  a;}

Page 128: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

C

A

B

slab head

another_obj  =  allocate(&shared_slab);

some_object  =  allocate(&shared_slab);

obj  *allocate(slab  *s)  {    obj  *a,  *b;    do  {        a  =  s-­‐>head;        if  (a  ==  NULL)  return  NULL;        b  =  a-­‐>next;    }  while  (!cas(a,  b,  &s-­‐>head));    return  a;}

Page 129: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

B

C

A

slab head

another_obj  =  allocate(&shared_slab);

free(&shared_slab,  some_object);

obj  *allocate(slab  *s)  {    obj  *a,  *b;    do  {        a  =  s-­‐>head;        if  (a  ==  NULL)  return  NULL;        b  =  a-­‐>next;    }  while  (!cas(a,  b,  &s-­‐>head));    return  a;}

Page 130: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

B

C

A

slab head

another_obj  =  allocate(&shared_slab);

free(&shared_slab,  some_object);

obj  *allocate(slab  *s)  {    obj  *a,  *b;    do  {        a  =  s-­‐>head;        if  (a  ==  NULL)  return  NULL;        b  =  a-­‐>next;    }  while  (!cas(a,  b,  &s-­‐>head));    return  a;}

Page 131: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

B

A Cslab head

another_obj  =  allocate(&shared_slab);

obj  *allocate(slab  *s)  {    obj  *a,  *b;    do  {        a  =  s-­‐>head;        if  (a  ==  NULL)  return  NULL;        b  =  a-­‐>next;    }  while  (!cas(a,  b,  &s-­‐>head));    return  a;}

free(&shared_slab,  some_object);

Page 132: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

B

A Cslab head

another_obj  =  allocate(&shared_slab);

obj  *allocate(slab  *s)  {    obj  *a,  *b;    do  {        a  =  s-­‐>head;        if  (a  ==  NULL)  return  NULL;        b  =  a-­‐>next;    }  while  (!cas(a,  b,  &s-­‐>head));    return  a;}

free(&shared_slab,  some_object);

Page 133: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

B

A Cslab head

another_obj  =  allocate(&shared_slab);

obj  *allocate(slab  *s)  {    obj  *a,  *b;    do  {        a  =  s-­‐>head;        if  (a  ==  NULL)  return  NULL;        b  =  a-­‐>next;    }  while  (!cas(a,  b,  &s-­‐>head));    return  a;}

free(&shared_slab,  some_object);

Page 134: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

B

A Cslab head

another_obj  =  allocate(&shared_slab);

obj  *allocate(slab  *s)  {    obj  *a,  *b;    do  {        a  =  s-­‐>head;        if  (a  ==  NULL)  return  NULL;        b  =  a-­‐>next;    }  while  (!cas(a,  b,  &s-­‐>head));    return  a;}

free(&shared_slab,  some_object);

Page 135: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

free(&shared_slab,  some_object);

B

B Cslab head

A

another_obj  =  allocate(&shared_slab);

obj  *allocate(slab  *s)  {    obj  *a,  *b;    do  {        a  =  s-­‐>head;        if  (a  ==  NULL)  return  NULL;        b  =  a-­‐>next;    }  while  (!cas(a,  b,  &s-­‐>head));    return  a;}

Page 136: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

free(&shared_slab,  some_object);

B

B Cslab head

A

another_obj  =  allocate(&shared_slab);

obj  *allocate(slab  *s)  {    obj  *a,  *b;    do  {        a  =  s-­‐>head;        if  (a  ==  NULL)  return  NULL;        b  =  a-­‐>next;    }  while  (!cas(a,  b,  &s-­‐>head));    return  a;}

Page 137: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

free(&shared_slab,  some_object);

B

B Cslab head

A

another_obj  =  allocate(&shared_slab);

obj  *allocate(slab  *s)  {    obj  *a,  *b;    do  {        a  =  s-­‐>head;        if  (a  ==  NULL)  return  NULL;        b  =  a-­‐>next;    }  while  (!cas(a,  b,  &s-­‐>head));    return  a;}

Page 138: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

The ABA Problem

“A reference about to be modified by a CAS changes from a to b and back to a again. As a result, the CAS succeeds even though its effect on the data structure has changed and no longer has the desired effect.” —Herlihy & Shavit, p. 235

Page 139: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

obj  *allocate(slab  *s)  {    obj  *a,  *b;    do  {        a  =  s-­‐>head;        if  (a  ==  NULL)  return  NULL;        b  =  a-­‐>next;    }  while  (!cas(a,  b,  &s-­‐>head));    return  a;}

A B …slab head166

Page 140: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

obj  *allocate(slab  *s)  {    slab  orig,  update;    do  {        orig.gen  =  s.gen;        orig.head  =  s.head;        if  (!orig.head)  return  NULL;          update.gen  =  orig.gen  +  1;        update.head  =  orig.head-­‐>next;    }  while  (!dcas(&orig,  &update,  s));    return  orig.head;}

A B …slab head166

Page 141: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

free(slab  *s,  obj  *o)  {          do  {                  obj  *t  =  s-­‐>head;                  o-­‐>next  =  t;          }  while  (!cas(t,  o,  &s-­‐>head));  }

Page 142: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

obj  *allocate(slab  *s)  {    lock(&allocator_lock);    obj  *a  =  s-­‐>head;    if  (a  ==  NULL)  return  NULL;    s-­‐>head  =  a-­‐>next;    unlock(&allocator_lock);    return  a;}  

void  free(slab  *s,  obj  *o)  {    lock(&allocator_lock);      o-­‐>next  =  s-­‐>head;    s-­‐>head  =  o;    unlock(&allocator_lock);  }

Page 143: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

slab head A B …

obj  *o  =  allocate(&shared_slab);

obj  *o  =  allocate(&shared_slab);

Page 144: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

slab head B …

obj  *o  =  allocate(&shared_slab);

obj  *o  =  allocate(&shared_slab);

A

A

Page 145: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

slab head B …

obj  *o  =  allocate(&shared_slab);

obj  *o  =  allocate(&shared_slab);

A

A

Memory barriers

Page 146: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

   lock(&allocator_lock);    obj  *a  =  s-­‐>head;…

   lock(&allocator_lock);    obj  *a  =  s-­‐>head;…

Page 147: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

   while  (atomic_tas(m,  LOCKED)  ==  LOCKED)          snooze();    obj  *a  =  s-­‐>head;…

   while  (atomic_tas(m,  LOCKED)  ==  LOCKED)          snooze();    obj  *a  =  s-­‐>head;…

Page 148: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

   LDREX  R5,  [m]                      ;  TAS:  fetch.  .  .      STREXEQ  R5,  LOCKED,  [m]  ;  TAS:  .  .  .  and  set      CMPEQ  R5,  #0                        ;  Did  we  succeed?

 LDR  R0,  [R1,  4]                  ;  a  =  s-­‐>head

   BEQ  lock_done                      ;  Yes:  we  are  all  done    BL  snooze                              ;  No:  Call  snooze()…    B  lock_loop                          ;          …then  loop  again lock_done:      B  LR                                        ;  return

;;;;  IN  lock()  lock_loop:  

;;;;  IN  allocate()  

Page 149: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

   LDREX  R5,  [m]                      ;  TAS:  fetch.  .  .      STREXEQ  R5,  LOCKED,  [m]  ;  TAS:  .  .  .  and  set      CMPEQ  R5,  #0                        ;  Did  we  succeed?

 LDR  R0,  [R1,  4]                  ;  a  =  s-­‐>head

   BEQ  lock_done                      ;  Yes:  we  are  all  done    BL  snooze                              ;  No:  Call  snooze()…    B  lock_loop                          ;          …then  loop  again lock_done:      B  LR                                        ;  return

;;;;  IN  allocate()  

;;;;  IN  lock()  lock_loop:  

Page 150: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

 LDR  R0,  [R1,  4]                  ;  a  =  s-­‐>head

   BEQ  lock_done                      ;  Yes:  we  are  all  done    BL  snooze                              ;  No:  Call  snooze()…    B  lock_loop                          ;          …then  loop  again lock_done:      B  LR                                        ;  return

;;;;  IN  allocate()  

   LDREX  R5,  [m]                      ;  TAS:  fetch.  .  .      STREXEQ  R5,  LOCKED,  [m]  ;  TAS:  .  .  .  and  set      CMPEQ  R5,  #0                        ;  Did  we  succeed?

;;;;  IN  lock()  lock_loop:  

Page 151: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

McKenney , p. 504

Page 152: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

McKenney , p. 504

Page 153: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

McKenney , p. 504

Page 154: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

McKenney , p. 504

Page 155: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software
Page 156: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

   LDREX  R5,  [m]                      ;  TAS:  fetch.  .  .      STREXEQ  R5,  LOCKED,  [m]  ;  TAS:  .  .  .  and  set      CMPEQ  R5,  #0                        ;  Did  we  succeed?

 LDR  R0,  [R1,  4]                  ;  a  =  s-­‐>head

   BEQ  lock_done                      ;  Yes:  we  are  all  done    BL  snooze                              ;  No:  Call  snooze()…    B  lock_loop                          ;          …then  loop  again lock_done:      B  LR                                        ;  return

;;;;  IN  allocate()  

;;;;  IN  lock()  lock_loop:  

Page 157: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

   LDREX  R5,  [m]                      ;  TAS:  fetch.  .  .      STREXEQ  R5,  LOCKED,  [m]  ;  TAS:  .  .  .  and  set      CMPEQ  R5,  #0                        ;  Did  we  succeed?

 LDR  R0,  [R1,  4]                  ;  a  =  s-­‐>head

   BEQ  lock_done                      ;  Yes:  we  are  all  done    BL  snooze                              ;  No:  Call  snooze()…    B  lock_loop                          ;          …then  loop  again lock_done:      B  LR                                        ;  return

;;;;  IN  allocate()  

;;;;  IN  lock()  lock_loop:  

Page 158: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software
Page 159: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

   obj  *a  =  s-­‐>head;      lock(&allocator_lock);…

   obj  *a  =  s-­‐>head;    lock(&allocator_lock);…

Page 160: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

   lock(&allocator_lock);    obj  *a  =  s-­‐>head;…

   lock(&allocator_lock);    obj  *a  =  s-­‐>head;…

Page 161: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

   lock(&allocator_lock);      <  -­‐  -­‐  -­‐  -­‐  -­‐  -­‐  -­‐  -­‐  -­‐  -­‐>    obj  *a  =  s-­‐>head;…

   lock(&allocator_lock);      <  -­‐  -­‐  -­‐  -­‐  -­‐  -­‐  -­‐  -­‐  -­‐  -­‐>    obj  *a  =  s-­‐>head;…

Page 162: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software
Page 163: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

   LDREX  R5,  [m]                      ;  TAS:  fetch.  .  .      STREXEQ  R5,  LOCKED,  [m]  ;  TAS:  .  .  .  and  set      CMPEQ  R5,  #0                        ;  Did  we  succeed?    BEQ  lock_done                      ;  Yes:  we  are  all  done    BL  snooze                              ;  No:  Call  snooze()…    B  lock_loop                          ;          …then  loop  again lock_done:      DMB                                          ;  Ensure  all  previous  reads                                                      ;  have  been  completed      B  LR                                        ;  return

;;;;  IN  unlock()      MOV  R0,  UNLOCKED      DMB                            ;  Ensure  all  previous  reads  have                                        ;  been  completed      STR  R0,  LR

;;;;  IN  lock()  lock_loop:  

Page 164: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

nathan~$  cat  /proc/cpuinfo  |  grep  "physical.*0"  |  wc  -­‐l  16  nathan~$  cat  /proc/cpuinfo  |  grep  "model  name"  |  uniq  model  name  :  Intel(R)  Xeon(R)  CPU  E5-­‐2690  0  @  2.90GHz

Allocator performance

Page 165: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

Mill

ions

of A

lloc/

free

pairs

/ se

c

10

20

30

40

50

60

Threads

1

20.56822.392

50.52951.23452.721

T&S T&S-EB T&T&S CASpthread_mutex

Allocator Throughput

Page 166: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

Mill

ions

of A

lloc/

free

pairs

/ se

c

10

20

30

40

50

60

Threads

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

TAS T&T&S TAS + EBConcurrent Allocator pthread

Allocator Throughput

Page 167: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

Allocator latency

Page 168: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

Allocator latency

Threads

CPU

Cyc

les

Page 169: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

Allocator latency

Threads

CPU

Cyc

les

Page 170: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

Allocator latency

Threads

CPU

Cyc

les

Page 171: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

Allocator latency

Threads

CPU

Cyc

les

Page 172: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

https://github.com/fastly/uslab

Page 173: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

The lyf so short, the CAS so longe to lerne

• Cache coherency and NUMA architecture

• Transactional memory

Page 174: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

#thoughtleadership

Page 175: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

a safe race?

When is a race

Page 176: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software
Page 177: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

“lock-free programming is hard; let’s go ride bikes”?

Page 178: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

“lock-free programming is hard; let’s go ride bikes”?

• high-level performance necessitates an understanding of low level performance

Page 179: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

“lock-free programming is hard; let’s go ride bikes”?

• high-level performance necessitates an understanding of low level performance

• your computer is a distributed system

Page 180: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

“lock-free programming is hard; let’s go ride bikes”?

• high-level performance necessitates an understanding of low level performance

• your computer is a distributed system

• (optional third answer: it’s real neato)

Page 181: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software
Page 182: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software
Page 183: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software
Page 184: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software
Page 185: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software
Page 186: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software
Page 187: Racing To Win: Using Race Conditions to Build Correct and Concurrent Software

Come see us at the booth!

Nathan Taylor | nathan.dijkstracula.net | @dijkstracula

Thanks

credits, code, and additional material at https://github.com/dijkstracula/Surge2015/