Am I creating new threads or ultra waste??? 
Author Message
 Am I creating new threads or ultra waste???

Hello everyone,

I've never really though about this problem before. I'm executing a loop and in every pass I use a private class field "xxx"  to create a *new* instance of another class "clsXXX" that will be executed in another thread. The thread variable "oThread" is also a private class variable. Let's say the loop has executed one pass and xxx is equal to a new instance of clsXXX and oThread is a new thread.

What happens to these variables when pass two of the loop occurs?
Is the previously created thread destroyed?
Is "xxx" equal to yet another new instance of clsXXX?
What happens to the old instance of clsXXX (created on pass one)?

...
private clsXXX xxx = null;
private Thread oThread = null;

...

foreach ( string str in strcollect)
{

        xxx = new clsXXX();
        xxx.prop1 = str;
        xxx.prop2 = "Some other property assignment";

        oThread = new Thread( new ThreadStart( xxx.DoSomething ) );
        oThread.Start();

Quote:
}

...

Thanks!
Andrew Barfield



Sun, 15 Aug 2004 23:56:56 GMT  
 Am I creating new threads or ultra waste???

Oops wrong group. Sorry....

  Hello everyone,

  I've never really though about this problem before. I'm executing a loop and in every pass I use a private class field "xxx"  to create a *new* instance of another class "clsXXX" that will be executed in another thread. The thread variable "oThread" is also a private class variable. Let's say the loop has executed one pass and xxx is equal to a new instance of clsXXX and oThread is a new thread.

  What happens to these variables when pass two of the loop occurs?
  Is the previously created thread destroyed?
  Is "xxx" equal to yet another new instance of clsXXX?
  What happens to the old instance of clsXXX (created on pass one)?

  ...
  private clsXXX xxx = null;
  private Thread oThread = null;

  ...

  foreach ( string str in strcollect)
  {

          xxx = new clsXXX();
          xxx.prop1 = str;
          xxx.prop2 = "Some other property assignment";

          oThread = new Thread( new ThreadStart( xxx.DoSomething ) );
          oThread.Start();
  }
  ...

  Thanks!
  Andrew Barfield



Mon, 16 Aug 2004 00:02:23 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Correctly creating threads or wasting memory?

2. Am I wasting my time learning MFC?

3. I am creating a new query using ADOX and no matter

4. I am new to programming and am lost

5. Newbie: Creating new thread

6. BeginInvoke() creates a new thread?

7. Creating new windows with its own thread

8. Trying to create new CHtmlView from an event thread

9. Operator new is creating threads?

10. Operator new is creating threads

11. How many ways to create a new thread?

12. Can't create a new thread

 

 
Powered by phpBB® Forum Software