• Two threads –
• Both threads will sleep for 1 second before reading from the global array of strings
#include <iostream>
#include <thread>
#include <chrono>
using namespace std;
void func(int num)
{
cout << "----------------------------\n";
cout << "I'm waiting ms\n";
cout << "I'm " << num << " thread\n";
cout << "================================\n";
this_thread::sleep_for(chrono::milliseconds(1000));
}
void newThread(int ms = 1000)
{
thread nw(func, 1);
thread nw2(func, 2);
while (!nw.joinable() && !nw2.joinable())
;
nw.join();
nw2.join();
}
int main() {
newThread();
return 0;
}
Comments
Leave a comment