You are not even locking mutex.
boost::unique_lock< boost::mutex >( mtx );
It is parsed as declaration of variable mtx
with type boost::unique_lock< boost::mutex >
, initialized with default constructor. Instead you need to use constructor that takes reference to lockable object:
boost::unique_lock< boost::mutex > lock{mtx};