Original Post
Ok, i think i'm having some issues with threads messing up the main program by calling the same function twice at the same time so i'm trying to use the mutex and was wondering if i'm doing this right.
this is just a sample that i created that kind of represents my program. Now is this created? because this is what i have and it seems to not bw working. As you can see I don't want Variable A below being access by the one function when the other is using it.
[edited by - Ryanrk on July 31, 2002 6:33:16 PM]
//this is global
HANDLE mutex = CreateMutex(NULL, FALSE, NULL);
int main(){
while(1){
while(WaitForSingleObject(mutex, 0) != WAIT_OBJECT_0);
// call function A that uses variable A
ReleaseMutex(mutex);
}
return 1;
}
DWORD WINAPI thethread(LPVOID threadNo){
while(1){
while(WaitForSingleObject(mutex, 0) != WAIT_OBJECT_0);
//call function B that uses variable A
ReleaseMutex(mutex);
}
}