| Subject: How to tell if thread owns critical section? |
| Group: microsoft.public.winternals |
| Date: 5/30/2007 11:10:44 AM |
| From: "George" [Email Address Protection] |
Hello all, I have an app where I run a variable number of identical threads. In order to use "try-throw-catch" error handling I have "wrapped" the WorkerBee threads in the following function: void WorkerBeeWrapper(LPVOID lpParam) { EnterCriticalSection(&cs); try { WorkerBee( MYWORKSPACE* lpParam ); } catch(char* str) { // process errors I define } catch( ... ) { // process other errors } // problem is here ... LeaveCriticalSection(&cs); } The WorkerBee() function enters and exits the same critical section as it does it's job. My problem is this: How to tell in the WorkerBeeWrapper() function whether or not the ending thread owns the critical section. Because there may be an error exit, I do not know. The TryEnterCriticalSection does not help because I must exit the critical section as many times as I enter it, so success means I must exit at least once and maybe two times. How to tell? Same question. I think I must hack the critical section structure, but my attempts thus far have all crashed and burned. All docs I have found warn against messing with the structure. Any help, alternatives, clues, pointers to docs, etc. would be appreciated. Thanks in advance, George |
| Back |
| Subject: Re: How to tell if thread owns critical section? |
| Group: microsoft.public.winternals |
| Date: 6/7/2007 8:13:44 AM |
| From: "Roberto Baggio" [Email Address Protection] |
If you get past the line: EnterCriticalSection(&cs); then you own the critical section. "George" <JungleGeorge@newsgroup.nospam> wrote in message news:eClNYXuoHHA.1852@TK2MSFTNGP05.phx.gbl... > Hello all, > > I have an app where I run a variable number of identical threads. In order > to use "try-throw-catch" error handling I have "wrapped" the WorkerBee > threads in the following function: > > void WorkerBeeWrapper(LPVOID lpParam) > { > EnterCriticalSection(&cs); > > try > { > WorkerBee( MYWORKSPACE* lpParam ); > } > catch(char* str) > { > // process errors I define > } > catch( ... ) > { > // process other errors > } > > // problem is here ... > LeaveCriticalSection(&cs); > } > > The WorkerBee() function enters and exits the same critical section as it > does it's job. My problem is this: How to tell in the WorkerBeeWrapper() > function whether or not the ending thread owns the critical section. > Because there may be an error exit, I do not know. The > TryEnterCriticalSection does not help because I must exit the critical > section as many times as I enter it, so success means I must exit at least > once and maybe two times. How to tell? Same question. > > I think I must hack the critical section structure, but my attempts thus > far have all crashed and burned. All docs I have found warn against > messing with the structure. > > Any help, alternatives, clues, pointers to docs, etc. would be > appreciated. > > Thanks in advance, > George > > |
| Back |
| Subject: Re: How to tell if thread owns critical section? |
| Group: microsoft.public.winternals |
| Date: 6/7/2007 1:11:10 PM |
| From: "George" [Email Address Protection] |
Roberto, Thank you for that succinct observation. My question is more related to what happens in WorkerBeeWrapper when the thread returns. Then I do not know if WorkerBee was in the critical section or not (it could be an unplanned exception) unless I keep my own flags. That is the solution others have suggested. Thank you, George PS - I probably posted in the wrong place. At the time I did not realize this is for the Winternals tools. Sorry. "Roberto Baggio" <baggio94@telus.net> wrote in message news:ebx$tZRqHHA.3356@TK2MSFTNGP03.phx.gbl... > If you get past the line: > EnterCriticalSection(&cs); > > then you own the critical section. > > "George" <JungleGeorge@newsgroup.nospam> wrote in message > news:eClNYXuoHHA.1852@TK2MSFTNGP05.phx.gbl... >> Hello all, >> >> I have an app where I run a variable number of identical threads. In >> order to use "try-throw-catch" error handling I have "wrapped" the >> WorkerBee threads in the following function: >> >> void WorkerBeeWrapper(LPVOID lpParam) >> { >> EnterCriticalSection(&cs); >> >> try >> { >> WorkerBee( MYWORKSPACE* lpParam ); >> } >> catch(char* str) >> { >> // process errors I define >> } >> catch( ... ) >> { >> // process other errors >> } >> >> // problem is here ... >> LeaveCriticalSection(&cs); >> } >> >> The WorkerBee() function enters and exits the same critical section as it >> does it's job. My problem is this: How to tell in the WorkerBeeWrapper() >> function whether or not the ending thread owns the critical section. >> Because there may be an error exit, I do not know. The >> TryEnterCriticalSection does not help because I must exit the critical >> section as many times as I enter it, so success means I must exit at >> least once and maybe two times. How to tell? Same question. >> >> I think I must hack the critical section structure, but my attempts thus >> far have all crashed and burned. All docs I have found warn against >> messing with the structure. >> >> Any help, alternatives, clues, pointers to docs, etc. would be >> appreciated. >> >> Thanks in advance, >> George >> >> > > |
| Back |