SHARED_MEM=turn
echo pippo > $SHARED_MEM

processo(){ # name
 for i in $(seq 100); do
     while grep -v $1 $SHARED_MEM >/dev/null ; do true; done
     critical_session $1
     if test "$1" = "pippo"; then  
	 echo "pluto" > $SHARED_MEM;
     else
	 echo "pippo" > $SHARED_MEM;
     fi
     io
 done
}
critical_session(){ 
  for i in 1 2 3; do
      echo -n $1
      io
  done
  echo .
}

io(){
 dd if=/dev/zero of=/dev/null count=1000 2>/dev/null
}

processo pippo & processo pluto &
wait