YC Yc.W home Systems · C++ · AI Infrastructure
C & C++ · Note

C++ mutex (待验证)

Explore all C & C++ notes →

在使用std::mutex时,应该声明为全局或者类的静态成员变量。

class A
{
public:
  void f();
public:
  static std::mutex m_Mutex;
}

std::mutex _mu;
void A:f()
{
  std::lock_guard<std::mutex> guard1(_mu);
  {};
}

void A:f2()
{
  _mu.lock();
  {};
  _mu.unlock();
}

← Previous Static Analyzers-C++