When should I prefer the first piece of code to the second, and do they have fundamental differences
std::mutex mtx;
mtx.lock();
... //protected stuff
mtx.unlock();
... //non-protected stuff
mtx.lock();
... //etc
and
std::mutex mtx;
std::unique_lock<std::mutex> lck(mtx);
... //protected stuff
lck.unlock();
... //non-protected stuff
lck.lock();
... //etc
I do understand that lock_guard is basically a unique_lock without the lock and unlock functions, but I'm having hard time differentiating a mutex and a lock using a mutex.