d******i 发帖数: 7160 | | d******i 发帖数: 7160 | | X****r 发帖数: 3557 | 3 Why do you want this piece of information?
I don't think there is such API, even there is,
by the time the API returns the thread state could
already be different.
One way to do it (probably not what you want) is
to call SuspendThread. It returns the thread's
previous suspend count, in addition to suspend the
thread. So now you know both its previous state,
and its current state. Call ResumeThread afterwards
if you don't intend to suspend the thread.
【在 d******i 的大作中提到】 : 或者被Suspend的状态? : 谢谢!
| d******i 发帖数: 7160 | 4 the thing is a thread is waiting there by ITSELF, not a result of an
external suspending action.
IMO, external suspending is not recommended for a safe programming since the
caller has no idea of the point where the suspended thread stops.
【在 X****r 的大作中提到】 : Why do you want this piece of information? : I don't think there is such API, even there is, : by the time the API returns the thread state could : already be different. : One way to do it (probably not what you want) is : to call SuspendThread. It returns the thread's : previous suspend count, in addition to suspend the : thread. So now you know both its previous state, : and its current state. Call ResumeThread afterwards : if you don't intend to suspend the thread.
| X****r 发帖数: 3557 | 5 Again, why you want to know whether a thread is waiting or not?
If you want to synchronize execution of threads, just use
synchronization functions. If you want your worker thread
can be ended while waiting for some object, make it wait for
multiple objects instead, and let your control thread signal
an object to tell it to exit. Only synchronization functions
are safe when communicating between threads. If you attempt
to check whether or not the worker thread is waiting from the
control thread, the information you get could already be
out-of-date and you still can't safely terminate it anyhow.
the
【在 d******i 的大作中提到】 : the thing is a thread is waiting there by ITSELF, not a result of an : external suspending action. : IMO, external suspending is not recommended for a safe programming since the : caller has no idea of the point where the suspended thread stops.
|
|