Hello i am trying to run two functions at the same time. Because i want to learn to make a timer or countdown of some kind.
And i have an idea on how to do so. But when i create two threads.
I get no output in my console application.
Here is my code.
#include <iostream>
#include <Windows.h>
#include <thread>
#include <random>
#include <string>
void timer()
{
int x{ 0 };
if (x < 1000)
{
std::cout << x++;
Sleep(1000);
}
}
void timer2()
{
int x{ 0 };
if (x < 10000)
{
std::cout << x++;
Sleep(1000);
}
}
int main()
{
std::thread one(timer);
std::thread two(timer2);
one.detach();
two.detach();
return 0;
}