| Subject: Thread suspend count |
| Group: microsoft.public.vstudio.general |
| Date: 8/13/2008 7:12:51 AM |
| From: "Alain Dekker" [Email Address Protection] |
Hi, If I create a thread in the non-suspended state and then call: SuspendThread(hThread); how do I know that the thread isn't already suspended when I call this? Ideally, I'd like something like this: if (GetThreadSuspendCount(hThread) == 0) SuspendThread(hThread); but the MSDN documentation is a little unhelpful here. Thanks, Alain |
| Back |
| Subject: Re: Thread suspend count |
| Group: microsoft.public.vstudio.general,microsoft.public.win32.programmer.kernel |
| Date: 8/20/2008 8:16:14 PM |
| From: "Alexander Grigoriev" [Email Address Protection] |
Though this is offtopic here: Suspending a thread is an operation which should not be used in most designs. It only makes sense when you develop a debugger. Suspending a thread in the same process is very dangerous operation, because it may leave you with an owned critical section; this will lead to a deadlock. If you suspend a thread (suppose it's an external debugger), you should not care if a thread is already suspended; you can call SuspendThread anyway. You shoud only be concerned that you don't call ResumeThread more times than you SuspendThread. For debugging purposes, SuspendThread returns current suspend count. The thread suspend cound in theory could change at any moment. In practice, if only you mess with thread suspend, you should know the count anyway. "Alain Dekker" <alain.dekker@NO.SPAM.loma.com> wrote in message news:umfBP5U$IHA.3392@TK2MSFTNGP03.phx.gbl... > Hi, > > If I create a thread in the non-suspended state and then call: > > SuspendThread(hThread); > > how do I know that the thread isn't already suspended when I call this? > Ideally, I'd like something like this: > > if (GetThreadSuspendCount(hThread) == 0) > SuspendThread(hThread); > > but the MSDN documentation is a little unhelpful here. > > Thanks, > Alain > |
| Back |