resource CS()
  const int N = 20   # number of processes
  int x = 0      # shared variable
  sem mutex = 1  # mutual exclusion for x
  process p [ i = 1 to N ] {
    # non-critical section
    # critical section
    P(mutex)  # enter critical section
    write(i," has mutex")
    x = x+1
    V(mutex)  # exit critical section
    # non-critical section
  }
end
