Create algo for critical section