Multithreading in C++

https://www.educative.io/blog/modern-multithreading-and-concurrency-in-cpp

C++ Threading:

https://www.youtube.com/watch?v=wXBcwHwIt_I

Example code run:
#include<iostream>
#include<thread>

static bool s_Finished=false;


void DoWork(){

   
   using namespace std::literals::chrono_literals;

    std::cout<<"Started thread id="<<std::this_thread::get_id()<<std::endl;

    while(!s_Finished)
    {
        std::cout<<"Working ....\n";
        std::this_thread::sleep_for(1s);
    }

}

int main(){
    std::thread worker(DoWork);

    std::cin.get();
    s_Finished=true;
    
    worker.join();
    std::cout<<"Finished"<<std::endl;

    std::cin.get();
}
It would be a great help, if you support by sharing :)
Author: zakilive

Leave a Reply

Your email address will not be published. Required fields are marked *