views:

43

answers:

2

Hi all,

I want to know the current state(SUSPENDED/READY/RUNNING/WAITING state ) of a thread which has been created by CreateThread() api.

How can I find it out?

My developement environment is Visual studio 2008 Expresss edition

also language is C/C++

/renjith g

+1  A: 

As has been previously answered :-

http://stackoverflow.com/questions/1006691/how-to-check-if-a-win32-thread-is-running-or-in-suspended-state/1007295#1007295

APIs that provide this information are not provided because the information they return is stale before they return. If you want to know if a thread is suspended - call SuspendThread. Now you know (a) the thread has a suspend count of at least 1, and, as SuspendThread returns the 'previous' suspend count, you can know that, at some point during the call to SuspendThread, the suspend count was 0, or some number. The same logic holds for testing if a thread is "stuck" in WaitForXObject(s) :- until you've stopped the thread, you can't know the answer to that question safely.

Chris Becke
A: 

You may find this Thread Status Monitor (free) useful for viewing the state of threads in your app.

Stephen Kellett