Board index » cppbuilder » How to determine if a Thead is suspended or not?

How to determine if a Thead is suspended or not?


2004-11-11 03:56:26 PM
cppbuilder80
Hi,
Does a Thead have any variable that can tell me if the thread is suspended or running?
I need to check this variable at several places in my code to know if i should send
Resume() command or Suspend() command to the thread, i guess that if such variable is
not exist i can create one like this by myself, i'll just define boolean variable for
each thread...
Thanks,
Ramy
 
 

Re:How to determine if a Thead is suspended or not?

"Ramy" < XXXX@XXXXX.COM >wrote:
Quote

Does a Thead have any variable that can tell me if the
thread is suspended or running?
Yes.
~ JD
 

Re:How to determine if a Thead is suspended or not?

Which is...... ?
"JD" < XXXX@XXXXX.COM >wrote:
Quote

"Ramy" < XXXX@XXXXX.COM >wrote:
>
>Does a Thead have any variable that can tell me if the
>thread is suspended or running?

Yes.

~ JD
 

{smallsort}

Re:How to determine if a Thead is suspended or not?

"Ramy" < XXXX@XXXXX.COM >wrote:
Quote

Which is...... ?
I was hoping that my one word reply would prompt you to do the
same as I ... look in the help for TThread.
It's the Suspended property. Be sure to read what Chris had to
say.
~ JD
 

Re:How to determine if a Thead is suspended or not?

"Ramy" < XXXX@XXXXX.COM >writes:
Quote
Hi,

Does a Thead have any variable that can tell me if the thread is
suspended or running?

I need to check this variable at several places in my code to know
if i should send Resume() command or Suspend() command to the
thread, i guess that if such variable is not exist i can create one
like this by myself, i'll just define boolean variable for each
thread...
While TThread has a Suspended property that you can read, it's not
100% reliable, because you can change the thread setting directly with
the OS, and the the TThread is out of synch with reality. So "don't
do that" and you should be ok using TThread's state.
A TThread is really just an object. A regular, boring C++ object. It
is not really a thread. It does, however, ask the OS to launch a
thread (that happens to begin life calling a member function of that
object.)
So it's important to think of the two as distinctly different things.
One is a C++ object, the other is an OS-controlled entity that is
executing your program's instructions and changing your program's
state. The TThread is a facade trying to give the impression that the
thread runs "in" it, but nothing requires that that happens if the
first thing in Execute calls into other objects, then the thread is
already in other code...)
Changing the TThread object's settings (like Suspended) asks the OS to
change the real thread's state. BUT, if you have the thread id you
can go outside the TThread object and ask the OS to do things
yourself. Thus, it's entirely possible (though hopefully not likely)
that your TThread object says the state is one thing, but the state of
the thread is really another.
If you exclusively limit your code to only modify the thread state
through the TThread provided interface, then it should accurately
reflect the state of the thread, though.
-
Chris (TeamB);
 

Re:How to determine if a Thead is suspended or not?

Thanks very much for the detail explenation, and yes, only my Code is modify the
State of the Threads so there is not a problem.
Ramy.
Chris Uzdavinis (TeamB) < XXXX@XXXXX.COM >wrote:
Quote
"Ramy" < XXXX@XXXXX.COM >writes:

>Hi,
>
>Does a Thead have any variable that can tell me if the thread is
>suspended or running?
>
>I need to check this variable at several places in my code to know
>if i should send Resume() command or Suspend() command to the
>thread, i guess that if such variable is not exist i can create one
>like this by myself, i'll just define boolean variable for each
>thread...

While TThread has a Suspended property that you can read, it's not
100% reliable, because you can change the thread setting directly with
the OS, and the the TThread is out of synch with reality. So "don't
do that" and you should be ok using TThread's state.

A TThread is really just an object. A regular, boring C++ object. It
is not really a thread. It does, however, ask the OS to launch a
thread (that happens to begin life calling a member function of that
object.)

So it's important to think of the two as distinctly different things.
One is a C++ object, the other is an OS-controlled entity that is
executing your program's instructions and changing your program's
state. The TThread is a facade trying to give the impression that the
thread runs "in" it, but nothing requires that that happens if the
first thing in Execute calls into other objects, then the thread is
already in other code...)

Changing the TThread object's settings (like Suspended) asks the OS to
change the real thread's state. BUT, if you have the thread id you
can go outside the TThread object and ask the OS to do things
yourself. Thus, it's entirely possible (though hopefully not likely)
that your TThread object says the state is one thing, but the state of
the thread is really another.

If you exclusively limit your code to only modify the thread state
through the TThread provided interface, then it should accurately
reflect the state of the thread, though.

-
Chris (TeamB);
 

Re:How to determine if a Thead is suspended or not?

Yes, i knew from the beginnig that that's what you's trying to do, but i was just too
busy to check it myself, but now i did, i guess that it's the 'Suspended' variable.
Thanks,
Ramy
Quote
I was hoping that my one word reply would prompt you to do the
same as I ... look in the help for TThread.

It's the Suspended property. Be sure to read what Chris had to
say.

~ JD