Boolean waiting[n], lock ; to be initialize to false
while(1) {
waiting[i]=true;
key= true;
while ( waiting[i] && key )
key=TestAndSet(lock);
waiting[i]=false;
//critical section;
j= (i+1) % n ;
while ((j != i) && !waiting[j])
j= (j+1) % n ;
if (j == i) lock = false ;
else waiting[j] = false ;
//reminder section;
}