CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Create threads

  1. #1
    Join Date
    Sep 2010
    Posts
    27

    Unhappy Create threads

    Hello buddies,

    I have a function that is to be used in an n-time loop
    That function is complex, so I am thinking if the following code snip is allowable to achieve what I'd like to


    Code:
    class Function
    {
     public:
        struct Fun
        {
           CWinThread** pt;
           void AllocThread(UINT n)
           {
              *pt=new CWinthread[n]
           }
               
        };
       void Loop(int n);
    }
    //bk-workerthread: say, usigned int BKWT(LPVOID lp) {call the complex function}

    //The loop function to hook up and use the bkwthread
    Code:
    void Function::Loop(int n)
    {  
        Fun*p=NULL;
        p.AllocThread(n);
        for(int i=0;i<n;i++)
        {
           p->pt[i]=afxbeginthread(xxxxxxxx);
        }
    }
    Someone please help me

    Thank you

  2. #2
    Join Date
    Jun 2009
    Location
    oklahoma
    Posts
    199

    Re: Create threads

    I have no idea what you are trying to ask but...
    Code:
    Fun *p = NULL;
    p.AllocThread(n);
    I am guessing you are getting a compiler error here.
    First, you say is is a pointer to nothing.
    Then you try to access p (even though you just said it points to nothing) with the . operator.
    Code:
    Fun *p = new Fun();
    ???

  3. #3
    Join Date
    Sep 2010
    Posts
    27

    Re: Create threads

    Thanks
    I'm trying to create n threads. It fails at AllocThread's new

  4. #4
    Join Date
    Jun 2009
    Location
    oklahoma
    Posts
    199

    Re: Create threads

    I don't think you have to call new...
    AfxBeginThread returns a pointer to the thread object... it already creates it for you
    I'd actually keep a list of the threads.

    Get rid of the AllocThread function.
    Code:
    void Function::Loop(int n)
    {  
        std::list<CWinThread*> pt_list;
        for(int i=0;i<n;i++)
        {
           CWinThread *pt = afxbeginthread(xxxxxxxx);
           pt_list.push_back(pt);
        }
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured