Threads Question

After creating a CWinThread Class, does
the thread takes cpu time? it is only created, and does not perform any operations!
bacharAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mikeblasCommented:
The initialization of CWinThread takes CPU time, yes.  So does its shutdown.

What do you mean, specifically, by it "does not perform any operations"?

If you mean that your controlling fuction is empty, then all you're paying for is that initialization and shutdown.

If you mean that the controlling function sits in a loop, then the loop really does take CPU time to run.

If the function is blocking on a waitable object, it's taking no CPU resources; the OS doesn't schedule quantums to a thread that's blocked.

..B ekiM

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
bacharAuthor Commented:
whould it be better to suspend the thread? or, if the thread only created, it is better just to leave it initialized?
mikeblasCommented:
> whould it be better to suspend the thread?

Better than what other course of action?  What is it, exactly, that you're trying to do?

 > or, if the thread only created, it is better just to leave it initialized?

The alternative to leaving it initialized is to shut it down.  You should shut it down, of course, when you're done using it so that it can cleanup properly.

But I can't understand your follow-up questions; you've not given me enough information to judge what you're trying to do, or what your other choices might be.

..B ekiM
TryCommented:
CWinThread is not a thread, nor does it produce a thread of itself.  CWinThread is a class, and what a class produces, is an instance of itself, called an object.  Objects and threads are two very different things.  A thread describes a path of execution within a process; objects contains data, as well as a set of functions that manipulates the data.

CWinThread as a class, takes up CPU time when it is being created into an object, and more CPU time when that object is being destroyed.  Other than that, it just sits there until you do something with it.

A thread uses up CPU time when it is running, and none, when it is not running.  When you create a thread (any thread), it uses up some CPU time to complete its creation, but after that it does nothing until you put it to work (which is when it starts using up more CPU time).

Don't get CWinThread mixed up with a thread simply because its name has the word "thread" in it.  CWinThread is not a thread and you do not create a thread from it when you instantiate an object of its class.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.