Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <thread>
- #include <chrono>
- using namespace std;
- void sleep_fn() {
- while(true) {
- this_thread::sleep_for(1000ms);
- }
- }
- constexpr int threads_count = 100;
- int main()
- {
- array<thread, threads_count> threads;
- for (int i = 0; i < threads_count; i++)
- threads[i] = thread(sleep_fn);
- chrono::steady_clock::time_point begin = chrono::steady_clock::now();
- chrono::steady_clock::time_point end;
- for (int i = 0; i < 50; i++)
- end = chrono::steady_clock::now();
- cout << "Time difference = " << chrono::duration_cast<chrono::milliseconds>(end - begin).count() << "[ms]" << endl;
- for (int i = 0; i < threads_count; i++)
- threads[i].detach();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement