Alphadan
March 19th, 2011, 04:24 PM
Hi
i have a mutex declared and initialized on a CPP
HANDLE RqMutex;
int main(){
RqMutex=CreateMutex(NULL,FALSE,"LegRefMTI");
}
Then from another cpp on another thread
I refer to my mutex as:
extern HANDLE RqMutex;
then on the procedure i want to lock
I call:
for (RqIt = RqLst.begin(); RqIt != RqLst.end(); ++RqIt){ //Loop iterating the args to be passed
HANDLE hThread;
hThread=(HANDLE)_beginthreadex(NULL,0,(unsigned int (__stdcall *)(void *))StartRequest,(void*)RqIt->c_str(),0,NULL); //Starting thread
if (WaitForSingleObject(RqMutex, 60000) == WAIT_TIMEOUT){
//Times out after 1 minute of waiting
}
//here should only enter once (if i dont release the mutex)
}
inside of the thread started after i make the copy of my args passed to the thread by reference...
only after i have the copy of the args( (void*)RqIt->c_str() ) on the other thread (on stack) then I release the mutex.
but there is a problem i commented the relese mutex and the beginthread starts 3 threads after locking.
i should only start one since i never released the mutex since i commented the release mutex the mutex isnt being released on another thread or cpp either.
does anyone knows whats wrong??
Thx in advance.
i have a mutex declared and initialized on a CPP
HANDLE RqMutex;
int main(){
RqMutex=CreateMutex(NULL,FALSE,"LegRefMTI");
}
Then from another cpp on another thread
I refer to my mutex as:
extern HANDLE RqMutex;
then on the procedure i want to lock
I call:
for (RqIt = RqLst.begin(); RqIt != RqLst.end(); ++RqIt){ //Loop iterating the args to be passed
HANDLE hThread;
hThread=(HANDLE)_beginthreadex(NULL,0,(unsigned int (__stdcall *)(void *))StartRequest,(void*)RqIt->c_str(),0,NULL); //Starting thread
if (WaitForSingleObject(RqMutex, 60000) == WAIT_TIMEOUT){
//Times out after 1 minute of waiting
}
//here should only enter once (if i dont release the mutex)
}
inside of the thread started after i make the copy of my args passed to the thread by reference...
only after i have the copy of the args( (void*)RqIt->c_str() ) on the other thread (on stack) then I release the mutex.
but there is a problem i commented the relese mutex and the beginthread starts 3 threads after locking.
i should only start one since i never released the mutex since i commented the release mutex the mutex isnt being released on another thread or cpp either.
does anyone knows whats wrong??
Thx in advance.