0

I am new to C++ & Multithreading. Recently taking a look at the Lock property...

Suppose I have a class with a mutex inside. When I use the lock method on the mutex object, how can I tell which part of the code is blocked/locked? Does it block/lock ALL the member functions inside the class or only the member function in which I triggered the lock?

e.g. (process_data & udf_2)

class data_wrapper
{
private:
    int x;
    some_data data;
    std::mutex m;
public:
    template<typename Function>
    void process_data(Function func)
    {
        std::lock_guard<std::mutex> l(m);
    ......
    }
    void udf_2(int x)
    {
        cout << "Value is " << x; 
    ......
    }
}

=============================

=============================

One more question is that if I saw a template type T, then what's mean by T& and T&&?

4

3 に答える 3