equivalent version using unique_lock