lock implementation