educative.io

Undefined behaviour using std::lock and std::lock_guard example?

In the example outlining the usage of std::lock with std::lock_guard, shouldn’t std::lock be placed before the two std::lock_guard(foo.mut, std::adopt_lock)?

My reasoning:
If for some reason an exception is thrown in the middle of the execution of the thread before std::lock is called, the lock_guard would go out of scope. This would cause it to call its destructor which tries to unlock the mutex, which in turn is not locked.