queue and lock implementation