book: typos fix in ch07-thread (#118)

revise the code to make sure it consistent with the book description
This commit is contained in:
changdingfang
2020-08-28 23:24:05 +08:00
committed by GitHub
parent a3f9aaa394
commit 518c6e97d7
3 changed files with 12 additions and 9 deletions

View File

@@ -15,15 +15,15 @@
using namespace std;
using namespace std::chrono;
atomic<int> counter = {0};
const int N = 10000;
void relaxed_order() {
cout << "relaxed_order: " << endl;
atomic<int> counter = {0};
vector<thread> vt;
for (int i = 0; i < N; ++i) {
vt.emplace_back([](){
vt.emplace_back([&](){
counter.fetch_add(1, memory_order_relaxed);
});
}
@@ -86,9 +86,10 @@ void release_acquire_order() {
void sequential_consistent_order() {
cout << "sequential_consistent_order: " << endl;
atomic<int> counter = {0};
vector<thread> vt;
for (int i = 0; i < N; ++i) {
vt.emplace_back([](){
vt.emplace_back([&](){
counter.fetch_add(1, memory_order_seq_cst);
});
}