Threading in C++ Example with Code

 

Threading in C++ Example with Code


#include <bits/stdc++.h>
#include<thread>
#include<unistd.h>
using namespace std;

void solve() {
for (int i = 0; i < 10; i++)
{
  sleep(1);
  cout<<i<<endl;
  fflush(stdout);
}

}

void solve2(){
  for (int i = 20; i < 30; i++)
{
  sleep(1);
  cout<<i<<endl;
  fflush(stdout);
}
}

int32_t main()
{

  thread t1(solve);
  thread t2(solve2);

  t1.join();
  t2.join();
  return 0;
}


c++ multithreading multithreading in c c++ thread example c++ create thread multithreading in cpp thread cpp create thread c++ c++ multithreading tutorial cpp multithreading

Post a Comment

0 Comments