Code:
#include <iostream>
#include <windows.h>
#include <process.h>
int x = 0, y = 0;
void myFunc( void* arg ) {
for(;;) {
++x;
++y;
}
}
int main() {
_beginthread( myFunc, 0, 0 );
for(;;) {
std::cout <<x <<" " <<y <<"\n";
}
}
My problem is that x and y are always 0, but if i had a sleep() to the threads entry function:
Code:
void myFunc( void* arg ) {
for(;;) {
++x;
++y;
Sleep(100); //Or even Sleep( 1 )
}
}
x and y change correctly. Why is that?
Just to make it clear, ive just started with multithreaded programming.