**Bernstein’s Conditions** are the conditions applied on two statements S1 and S2 that are to be executed in the processor. It states that three conditions that are explained below must be satisfied for two successive statements S1 and S2 to be executed concurrently and still produce the same result.

The intersection between read-write set, write-read set and write-write set of S1 and S2 must be null.

The above statement can be expressed in the form of expressions as following:

1.R(S1) ∩ W(S2) = { }2.W(S1) ∩ R(S2) = { }3.W(S1) ∩ W(S2) = { }

The read and write set for the statement c = a – b;

R(c=a-b) = {a, b} W(c=a-b) = {c}

The read and write set for the statement w = c + 1;

R(w=c+1) = {c} W(w=c+1) = {w}

The read and write set for the statement x = x + 2;

R(x=x+2) = {x} W(x=x+2) = {x}

**Example-1:**

Let,

S1 : a = x + y S2 : b = z + 1

Check whether two statements S1 and S2 satisfies Bernstein’s conditions.**Solution:**

R(S1) = {x, y} W(S1) = {a} R(S2) = {z} W(S2) = {b}1.R(S1) ∩ W(S2) = {x, y} ∩ {b} = { }2.W(S1) ∩ R(S2) = {a} ∩ {z} = { }3.W(S1) ∩ W(S2) = {a} ∩ {b} = { }

Therefore S1 ans S2 can be executed concurrently i.e., Bernstein’s conditions are satisfied.

**Example-2:**

Let,

S1 : a = x + y S2 : b = z + 1 S3 : c = a - b

Check whether two statements S2 and S3 satisfies Bernstein’s conditions.

**Solution:**

R(S2) = {z} W(S2) = {b} R(S3) = {a, b} W(S3) = {c}1.R(S2) ∩ W(S3) = {z} ∩ {c} = { }2.W(S2) ∩ R(S3) = {b} ∩ {a, b} = {b}3.W(S2) ∩ W(S3) = {b} ∩ {c} = { }

Therefore S2 ans S3 cannot be executed concurrently i.e., Bernstein’s conditions are not satisfied.

Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the **CS Theory Course** at a student-friendly price and become industry ready.