Skip to content

Instantly share code, notes, and snippets.

@syoyo
Created October 25, 2015 06:12
Show Gist options
  • Save syoyo/d502bd890f9e32f159da to your computer and use it in GitHub Desktop.
Save syoyo/d502bd890f9e32f159da to your computer and use it in GitHub Desktop.
Simple task queue using C++11 thread&atomic
std::vector<std::thread> workers;
std::atomic<unsigned int> i(0);
for (auto t = 0; t < std::thread::hardware_concurrency(); t++){
workers.push_back(std::thread([&,t](){
int index = 0;
while((index = i++) < numItems){
...
}
}));
}
for(auto &t : workers){
t.join();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment