use peterson algo to protect semaphore