Created
February 5, 2018 23:17
-
-
Save toddlipcon/7b23f0a59ece6573b0bfc588d1b8cb68 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment