Help with simple multithreading.
(Borland c++ free command line compiler, WinXP)
I'm just trying to multithread something simple, I attempted to make a multithreaded version. Sence the multithreaded part of my code is short, but my actual code is long, I'll boil it down.
Code:
#include <windows.h>
#include <iostream>
#include <process.h>
using namespace std;
CRITICAL_SECTION CSector;
int Gravity(int rate) {
int y, x;
for(y=0; y <= rate; y++) {
EnterCriticalSection(&CSector);
cout << "Gravity";
LeaveCriticalSection(&CSector);
}
return 1;
}
int Move(int radius) {
int y, x;
for(y=0; y <= radius; y++) {
EnterCriticalSection(&CSector);
cout << "Move";
LeaveCriticalSection(&CSector);
}
return 1;
}
int main() {
HANDLE h[1];
InitializeCriticalSection(&CSector);
h[0] = (HANDLE)_beginthread(Gravity, 0, NULL);
h[1] = (HANDLE)_beginthread(Move, 0, NULL);
WaitForMultipleObjects(2, h, TRUE, INFINITE);
DeleteCriticalSection(&CSector);
return 0;
}
But I get:
Code:
Error E2268 C:\Threadtest.cpp 36: Call to undefined function '_beginthread' in function main()
*** 1 errors in Compile ***
?? I dont get why this is giving me an error -,-.