Hi
i have a mutex declared and initialized on a CPP
Then from another cpp on another threadCode:HANDLE RqMutex; int main(){ RqMutex=CreateMutex(NULL,FALSE,"LegRefMTI"); }
I refer to my mutex as:
then on the procedure i want to lockCode:extern HANDLE RqMutex;
I call:
inside of the thread started after i make the copy of my args passed to the thread by reference...Code: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) }
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.




Reply With Quote