-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy paththreadLimitTest.cpp
More file actions
44 lines (34 loc) · 1.18 KB
/
threadLimitTest.cpp
File metadata and controls
44 lines (34 loc) · 1.18 KB
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
36
37
38
39
40
41
42
43
44
#include <iostream>
#include <thread>
#include <chrono> // std::chrono::seconds
#include <atomic>
//g++ -std=c++17 threadLimitTest.cpp -lpthread -o binary
int main() {
unsigned int n = std::thread::hardware_concurrency();
std::cout << n << " concurrent threads are supported.\n";
std::atomic<int> a {1};
//for(int i = 0; i<100000; i++)
try
{
while(a > 0)
{
std::thread([&](){
while(1)
{
//a ++;
//std::cout<<a<<std::endl;
std::thread::id this_id = std::this_thread::get_id();
std::cout << this_id <<"\n";
std::this_thread::sleep_for(std::chrono::milliseconds(10000));
}
}).detach();
a ++;
}
}
catch(const std::exception& e)
{
std::cerr << e.what() << "max number of threads "<<a<<'\n';
return 0; // if uncomment this return, then although the error, progrma will continue
}
while(1);
}