#define N 3
#define NULL 255
byte b0, b1, b2;
byte x=NULL;
byte y=NULL;
bit inCS0, inCS1, inCS2;

#define PROC(NAME, B, ID, COMP, INCS)\
active proctype NAME()\
{\
byte j=0;\
NCS: if\
:: B = 1; goto q1;\
fi;\
CS: if\
:: y = NULL; goto e1;\
fi;\
q1: if\
:: x = ID; goto q2;\
fi;\
q2: if\
:: atomic {y!=NULL;B = 0;}  goto q22;\
:: y==NULL; goto p;\
fi;\
q22: if\
:: atomic{y==NULL;INCS=0;} goto NCS;\
fi;\
p: if\
:: y = ID; goto q3;\
fi;\
q3: if\
:: atomic{x==ID;INCS=1;} goto CS;\
:: atomic{x!=ID;B = 0;j = 0;}  goto q4;\
fi;\
q4: if\
::  atomic\
    {\
      if\
      ::j==0 && b0==0;\
      ::j==1 && b1==0;\
      ::j==2 && b2==0;\
      fi;\
      j = j+1;\
    } goto q4;\
:: j==N; goto q5;\
fi;\
q5: if\
:: atomic{y==COMP;INCS=1;} goto CS;\
:: atomic{y==NULL;INCS=0;} goto NCS;\
fi;\
e1: if\
:: atomic{B = 0;INCS=0;} goto NCS;\
fi;\
}



PROC(P_0, b0, 0, x, inCS0)

PROC(P_1, b1, 1, x, inCS1)

PROC(P_2, b2, 2, x, inCS2)

never
{
again:
  if
  :: true; goto again;
  :: (inCS0 + inCS1 + inCS2)>1;
  fi;
}
