Answer to Question #343317 in C++ for Priyanka

Question #343317

• Two threads –



• Both threads will sleep for 1 second before reading from the global array of strings

1
Expert's answer
2022-05-20T15:33:06-0400


#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS