Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <thread>
- #include <atomic>
- #include <vector>
- #include <unistd.h>
- using namespace std;
- int main() {
- vector<thread> threads;
- atomic<bool> done { false };
- for (int i = 0; i < 20; i++) {
- threads.emplace_back([&]() {
- while (!done) { usleep(10000); }
- });
- threads.back().detach();
- }
- done = true;
- sleep(1);
- return 0;
- }
Add Comment
Please, Sign In to add comment