Mutex is not copyable and not moveable. But you don't need either of these operatons, you only need to create sample_t
object - std::mutex
inside will be initilized by the compiler.
sample_t new_sample;
new_sample.mtx.lock();
new_sample.field1 = 2;
new_sample.mtx.unlock();
Or, if you really need a pointer for some reason :
// sample_t* new_sample = new sample_t;
// you should prefer smart pointers over raw pointers
std::unique_ptr<sample_t> new_sample = std::make_unique<sample_t>();
new_sample->mtx.lock();
new_sample->field1 = 2;
new_sample->mtx.unlock();
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…