Skip to content

Commit

Permalink
Improve example in README
Browse files Browse the repository at this point in the history
Use a counter on the stack instead of allocating it using new.
  • Loading branch information
davidklaftenegger committed Oct 26, 2016
1 parent 69dbce9 commit 03b4569
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions README.md
Expand Up @@ -61,20 +61,20 @@ Here is a minimal example for how to use them:
#include<iostream>
#include<qd.hpp>
int main() {
int* counter = new int;
int counter = 0;
qdlock lock;
std::thread threads[4];
for(auto& t : threads) {
t = std::thread(
[&lock, counter]() {
lock.delegate_n([counter]() { (*counter)++; });
[&lock, &counter]() {
lock.delegate_n([&counter]() { counter++; });
}
);
}
for(auto& t : threads) {
t.join();
}
std::cout << "The counter value is " << *counter << std::endl;
std::cout << "The counter value is " << counter << std::endl;
}
```

Expand Down

0 comments on commit 03b4569

Please sign in to comment.