In: Computer Science
C++ program
using Eclipse IDE
The C++ program should have concurrency.
The C++ program should create 2 threads that will act as counters. One thread should count down from 5 to 0. Once that thread reaches 0, then a second thread should be used to count up to 20.
check out the solution and DO COMMENT if any queries.
---------------------------------------------------------------------
#include<iostream>
//#include <mutex>
#include<thread>
using namespace std;
// counts from 5 to 0
void countDown()
{
for(int i=5; i>=0; i--)
{
cout << i << endl;
}
}
// counts from 0 to 20
void countUp()
{
for(int i=0; i<=20; i++)
{
cout << i << endl;
}
}
int main() {
// creation of 2 threads
thread thread1(countDown);
thread thread2(countUp);
// synchronize threads
thread1.join();
thread2.join();
}
----------------------------------------------
---------
OUTPUT ::