Created
October 25, 2015 06:12
-
-
Save syoyo/d502bd890f9e32f159da to your computer and use it in GitHub Desktop.
Simple task queue using C++11 thread&atomic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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