#include <iostream>
#include <thread>
#include <vector>
#include <algorithm>
#include <functional>
int main() {
std::vector<std::thread> threads;
for (int i = 0; i < 10; i++) {
threads.emplace_back([i] {
for (int j = 0; j < 3; j++) printf("%d\n", i);
});
}
std::for_each(threads.begin(), threads.end(), std::mem_fn(&std::thread::join));
return 0;
}
最后修改:2019 年 03 月 15 日
© 允许规范转载