Hi, I am learning Multithreadeding and I think I got what this site down ok, but when I went to run it, it still didnt do what I want it to do. See my program needs to run 2 loops, 1st loop is the time, it looks at the time on the sysem and shows you the time every 1 sec. 2end loop is the main program, it had to wait for input from the user so thats why they cant be togather in one thread. Maybe you can tell me what I can do differntly or some other way of doing it maybe? This is whats the base of the Multithreadeding half.
Code:#include <windows.h> #include <process.h> #include <iostream> using namespace std; void Func1(void *); void Func2(void *); CRITICAL_SECTION Section; int main() { HANDLE hThreads[2]; InitializeCriticalSection(&Section); hThreads[0] = (HANDLE)_beginthread(Func1,0,NULL); hThreads[1] = (HANDLE)_beginthread(Func2,0,NULL); WaitForMultipleObjects(2,hThreads,TRUE,INFINITE); DeleteCriticalSection(&Section); cout << "Main exit" << endl; return 0; } void Func1(void *P){ int Count; for (Count = 1; Count < 11; Count++){ EnterCriticalSection(&Section); cout << "Func1 loop " << Count << endl; LeaveCriticalSection(&Section);} return; } void Func2(void *P){ int Count; for (Count = 10; Count > 0; Count--){ EnterCriticalSection(&Section); cout << "Func2 loop " << Count << endl; LeaveCriticalSection(&Section);} return; }



LinkBack URL
About LinkBacks


