wakensky
wakensky

Reputation: 43

when will a std::lock_guard got locked?

I have the following codes. I wonder that whether the scoped lock got locked at the beginning of function "do_something"? Thanks very much!

class Test {
public:
    void do_something () {
        std::cout << "anything printable" << std::endl;
        // do something else
        // Has mu_ got locked here?
        ...

        std::lock_guard<std::mutex> l(mu_);
        // something only I can do
        ...

        return;
    }
private:
    std::mutex mu_;
}

Upvotes: 0

Views: 73

Answers (0)

Related Questions