小编Ant*_*kov的帖子

为什么 C++ 关联容器谓词默认不透明?

由于 C++14,我们std::less<void>在大多数情况下都是透明且更有用的,因此是否有原因,例如,默认情况下std::set仍将std::less<Key>其作为谓词,而不是std::less<void>历史原因除外。

有用的案例:std::set<std::string>::findwithstd::string_view

c++ containers predicate associative

4
推荐指数
1
解决办法
168
查看次数

原子类对象方法用法

我想从两个线程原子地调用某些类的方法.我有来自第三方库的非安全类,但需要像这样使用这个类:

主线程:

Foo foo;
foo.method1(); // while calling Foo::method1 object foo is locked for another threads
Run Code Online (Sandbox Code Playgroud)

第二个帖子:

foo.method2(); // wait while somewere calling another methods from foo
Run Code Online (Sandbox Code Playgroud)

在这种情况下如何使用std :: atomic?或者可能是另一种解决方案(从foo调用方法后排除使用互斥锁和锁定之前和解锁)?

c++ multithreading atomic c++11

2
推荐指数
1
解决办法
502
查看次数