You are on page 1of 22

Race Conditions; Critical and Non-Critical Races

A race condition occurs in an asynchronous circuit when 2 or more state variables change in response to a change in the value of a circuit input. Unequal circuit delays may imply that the 2 or more state variables may not change simultaneously this can cause a problem. Assume two state variables change If the circuit reaches the same final, stable state regardless of the order in which the state variables change, then the race in non-critical. If the circuit reaches a different final, stable state depending on the order in which the state variables change, then the race is critical.

We need to avoid critical races for predictability and to ensure our circuit does the intended function!

ECE124 Digital Circuits and Systems

Page 1

Non-Critical Race
Assume current state is 00, and input changes from 0->1. This requires y1y2 to change from 00->11.
x y1y2 00 curr state 01 11 10 0 1

00 11 00 01 00 01 00 11

Depending on circuit delays, several possible transition sequences: 00 -> 11 -> 01 (simultaneous change for y1 and y2). 00 -> 01 (y2 changes first). 00 -> 10 -> 11 -> 01 (y1 changes first)
In all cases, we end up in the same stable state, so the race is non-critical.
Page 2

ECE124 Digital Circuits and Systems

Critical Race
Assume current state is 00, and input changes from 0->1. This requires y1y2 to change from 00->11.
x y1y2 00 curr state 01 11 10 0 1

00 11 00 11 00 11 00 10

Possible transition sequences: 00->11 (y1 and y2 change simultaneously) 00->01->11 (y2 changes first) 00->10 (y1 changes first)

So, depending on which state variable changes first, we can get into a different stable state the race is critical.
Page 3

ECE124 Digital Circuits and Systems

Why Races Exist


Races are a consequence of how states are assigned when designing a circuit. That is, races exist in the transition tables, but not in the flow tables. This should be somewhat clear.

Races are a consequence of state variables changing at the same time and therefore cant happen until binary state assignment is done.
Flow tables are entirely symbolic, so no problems there

Transition tables have binary values assigned, so potential problems there

ECE124 Digital Circuits and Systems

Page 4

Stability and Cycles


We also need to be careful that our circuit does not become unstable. Assume current state is 00, and input changes from 0->1. This requires y1y2 to change from 00->01. x
y1y2 00 curr state 01 11 10 0 1 00 01 00 11 00 10 00 01

Transitions will be 00->01->11->10->01-> So, our circuit oscillates. If this was not our intention, we are in trouble.

Should have a stable state for each input condition and make sure we get to a stable state always.
ECE124 Digital Circuits and Systems Page 5

Race Free State Assignment


We can prevent races (pre-emptive) by performing state assignment such that transitions from one stable state to another stable state only require one state variable to change at a time. Can consider a few different methods for performing race-free state assignment.

ECE124 Digital Circuits and Systems

Page 6

Example
Consider an example flow table

curr state a b c d

next state x=0 a c c a x=1 b b d d

ECE124 Digital Circuits and Systems

Page 7

Example Transition Diagram


Build a transition diagram that shows transitions from one stable state to another stable state under a changing input. Each edge shows a possible transition. Each node represents a state.

curr state a b c d

next state x=0 a c c a x=1 b b d d

ECE124 Digital Circuits and Systems

Page 8

Example State Assignment (A Bad Choice)


Consider assigning binary patterns to states based on the co-ordinates of the state in the transition diagram:

10 c

11 d

a 00

b 01

This is a BAD assignment, since a transition from b->c or d->a requires two state variables to change simultaneously.

ECE124 Digital Circuits and Systems

Page 9

Example State Assignment (A Good Choice)


Consider shifting states to different co-ordinates:

10 d

11 c

a 00

b 01

This is a GOOD assignment, since a transition from b->c or d->a requires only one state variables to change.

ECE124 Digital Circuits and Systems

Page 10

Method One for Race Free State Assignment


Given a flow table, try and embed the symbolic states into the co-ordinates of a ndimensional cube such that the path from stable state to stable state: Is direct along a single edge of the cube, or Goes through newly introduced unstable states along edges of the cube.

ECE124 Digital Circuits and Systems

Page 11

Example
Consider the following flow table:

curr state a b c d

next state x1x2=00 a a c c x1x2=01 a b b a x1x2=10 c d c d x1x2=11 b b d d

ECE124 Digital Circuits and Systems

Page 12

Example Transition Diagram


We can attempt to embed 4 states into a 2-dimensional cube and draw the transition diagram:
curr state a b c d next state x1x2=00 a a c c x1x2=01 a b b a x1x2=10 c d c d x1x2=11 b b d d

If we try, we see that there is no way to re-arrange the states to the corners of the cube to get rid of the diagonals in the transition diagram No state assignment that has only one state variable changing at a time.

ECE124 Digital Circuits and Systems

Page 13

Example Transition Diagram


Solution is to introduce additional, unstable states and use them as intermediate states during transitions. I.e., embed the 4-states into the corners of a 3-dimensional cube.

d e c

b
a b

ECE124 Digital Circuits and Systems

Page 14

Example Transition Diagram


All transitions are made properly by introducing extra unstable states (Note: the new extra states are always unstable!!!):
110 d 010 100 c f 101 a 000 b 001 g 011 e

ECE124 Digital Circuits and Systems

Page 15

Example Race Free Flow Table


Can now see the original flow table, and an expanded flow table (extra unstable states) that has a race-free state assignment (see previous page!):

curr state a b c d

next state x1x2=00 a a c c x1x2=01 a b b a x1x2=10 c d c d x1x2=11 b b d d

curr state a b c d e f g

next state x1x2=00 a a c g c x1x2=01 a b b a b x1x2=10 c e c d d x1x2=11 b b g d d

ECE124 Digital Circuits and Systems

Page 16

Method Two for Race Free State Assignment


Method useful for flow tables with <= 4 states. Replace a state with multiple (two) equivalent states Note: Outputs must be the same for the equivalent states!!!

Best to do an example

ECE124 Digital Circuits and Systems

Page 17

Example

curr state a b c d

Consider the following flow table, and another (larger table) with equivalent states:
next state x1x2=00 a a c c x1x2=01 a b b a x1x2=10 c d c d x1x2=11 b b d d
curr state a1 a2 b1 b2 c1 c2 d1 d2 next state x1x2=00 a1 a2 a1 a2 c1 c2 c1 c2 x1x2=01 a1 a2 b1 b2 c2 b1 d2 d1 x1x2=10 c1 a1 b2 d2 c1 c2 d1 d2 x1x2=11 b1 b2 b1 b2 d1 d2 d1 d2

output 0 1 0 1

output 0 0 1 1 0 0 1 1

The flow table with equivalent states permits a race free state assignment. We can see this by looking at the states on a 3-dimensional cube.

ECE124 Digital Circuits and Systems

Page 18

Example
c2
curr state a1 a2 b1 b2 c1 c2 d1 d2 next state x1x2=00 a1 a2 a1 a2 c1 c2 c1 c2 x1x2=01 a1 a2 b1 b2 c2 b1 d2 d1 x1x2=10 c1 a1 b2 d2 c1 c2 d1 d2 x1x2=11 b1 b2 b1 b2 d1 d2 d1 d2 output 0 0 1 1 0 0 1 1

d2 b2

b1

c1 a1 a2

d1

With equivalent states, we always have 1 of the 2 equivalent states directly adjacent to every other state!

ECE124 Digital Circuits and Systems

Page 19

Method Three for Race Free State Assignment


Can use the idea of one-hot encoding to get a race free state assignment Given n-states, let the i-th state be encoded as 0010..0 where the 1 is in the i-th location. For a transition from i-th stable state to j-th stable state, introduce unstable state with encoding 0..010..010..0 where the 1s are in the i-th and j-th position. Again, best illustrated with an example

ECE124 Digital Circuits and Systems

Page 20

Example
Consider the following flow table, with one-hot state assignment:

curr state 0001 0010 0100 1000 a b c d

next state x1x2=00 a a c c x1x2=01 a b b a x1x2=10 c d c d x1x2=11 b b d d

Look for transitions and introduce new unstable states, as required using one-hot encoding scheme.

ECE124 Digital Circuits and Systems

Page 21

Example
curr state 0001 0010 0100 1000 a b c d next state x1x2=00 a a c c x1x2=01 a b b a x1x2=10 c d c d x1x2=11 b b d d

curr state 0001 0010 0100 1000 0101 0011 1010 0110 1100 1001 a b c d e f g h i i

next state x1x2=00 a f c c a c x1x2=01 a b h j b a x1x2=10 e g c d c d x1x2=11 f b i d b d -

ECE124 Digital Circuits and Systems

Page 22

You might also like