• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 166
  • Last Modified:

Threads Question

After creating a CWinThread Class, does
the thread takes cpu time? it is only created, and does not perform any operations!
0
bachar
Asked:
bachar
  • 2
1 Solution
 
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
0
 
bacharAuthor Commented:
whould it be better to suspend the thread? or, if the thread only created, it is better just to leave it initialized?
0
 
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
0
 
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.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now