C++ Examples

  1. Write a C++ Program to print a welcome text in a separate line.

Threading in C++

#include <iostream>
#include <thread>

using namespace std;

//function definations

void func1()
{
   cout<<"I am function 1"<<endl; 
}

void func2()
{
    cout<<"I am function 2";
}

int main()
{
    
    // Creation of threads
    
    thread th1(func1);
    thread th2(func2);
    
    //Joining of threads 
    
    th1.join();
    th2.join();

    return 0;
}

Output

I am function 1
I am function 2
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments