Peterson algorithm (stupid impl)