Skip to content

Instantly share code, notes, and snippets.

@wweic
Created September 10, 2016 05:21
Show Gist options
  • Save wweic/8e503f27dd06f275e5a6c2aae3be4b12 to your computer and use it in GitHub Desktop.
Save wweic/8e503f27dd06f275e5a6c2aae3be4b12 to your computer and use it in GitHub Desktop.
#include <thread>
int const NUM_THREADS = 5;
uint32_t counter[NUM_THREADS];
void driver(int threadId) {
for (int i = 0; i < 100000000; ++i) {
counter[threadId * 16]++;
}
}
int main() {
std::thread t1(driver, 0);
std::thread t2(driver, 1);
std::thread t3(driver, 2);
std::thread t4(driver, 3);
std::thread t5(driver, 4);
t1.join();
t2.join();
t3.join();
t4.join();
t5.join();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment