hi all! :)
well i wrote a sample code to test threads
and i don't get what i want
the problem is that the thread i created is starting directly after i create it?
but he must start when my j is equal to 25 and then i joining the thread
what is the problem?
screen: Result
code:
#include <iostream>
#include <thread>
#include <Windows.h>
using namespace std;
void f1()
{
for (int i = 0; i < 50; i++) {
cout << i << endl;
Sleep(100);
}
}
void f2()
{
cout << "Hello World1" << endl;
}
int main()
{
thread t1(f1);
for (int j = 0; j < 50; j++) {
if (j == 25)
t1.join();
cout << j << endl;
Sleep(500);
}
cin.get();
}
thanks in advance :)