Lock with timeout