So I was cold last night…

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <atomic>
#include <chrono>
#include <iomanip>
#include <iostream>
#include <string>
#include <thread>
#include <vector>
 
using namespace std;
 
int main()
{
	auto known_cores = thread::hardware_concurrency();
	auto cores = max(known_cores-1,decltype(known_cores){1});
 
	volatile bool done = false;
 
	auto f = [&](){	while(!done); };
 
	vector<thread> v;
	for(decltype(cores) i{0}; i < cores-1; ++i){
		v.push_back(thread{f});
	}
 
	string temp;
	getline(cin,temp);
 
	done = true;
 
	for(auto&& t : v){
		t.join();
	}
 
	return 0;
}

Leave a Reply

Your email address will not be published.