you must move it under scoped_lock, otherwise your algorithm is incorrect