Does std::mutexthe race condition for the mutex itself make the static condition
No, Mutex is not vulnerable to race conditions. And as for initializing it as staticyou are safe.
$6.7: 4: ([basic.stc.static]) ([basic.stc.thread]) ; . , , . ,
:
, std::mutex , , .
, - static. mutable. , , map , static , - .
class Map{
public:
Map(...){}
std::size_t size() const{
std::lock_guard<std::mutex> lck(m_m);
return m_size;
}
iterator add(....) {
std::lock_guard<std::mutex> lck(m_m);
....
return your_iterator;
}
...etc
private:
mutable std::mutex m_m;
...others
};
:
Map mp(... ...);