LockGuard for MFC CMutex
Instead of writing your own lock_guard-like object specifically to use with a CMutex, I'd write a wrapper for CMutex to give it the Lockable interface, then just use it with a normal std::lock_guard:

namespace mfc {
class mutex {
    CMutex m;
public:
    mutex(BOOL bInitiallyOwn = FALSE,  
          LPCTSTR lpszName = NULL,  
          LPSECURITY_ATTRIBUTES lpsaAttribute = NULL) 
        : m(bInitiallyOwn, lpszName, lpsaAttribute) 
    {}

    void lock() { m.Lock(); }
    void unlock() { m.Unlock(); }
};


Then you can just lock it like you would an std:mutex:

// Define the mutex
mfc::mutex m;

void foo() { 
    std::lock_guard&lt;mfc::mutex&gt; L(m);
    // use whatever m is protecting
}


You may not even need that though. You may have run into the fact that a Windows-native mutex is always a recursive mutex, and a std::mutex is not. If you replace it with std::recursive_mutex instead of std::mutex, it may work just fine (or depending on how you do your locking, you may need a recursive_timed_mutex).