Skip to content

Instantly share code, notes, and snippets.

@toddlipcon
Created February 5, 2018 23:17
Show Gist options
  • Save toddlipcon/7b23f0a59ece6573b0bfc588d1b8cb68 to your computer and use it in GitHub Desktop.
Save toddlipcon/7b23f0a59ece6573b0bfc588d1b8cb68 to your computer and use it in GitHub Desktop.
#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