-
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: :rolleyes: say, usigned int BKWT(LPVOID lp) {call the complex function}
//The loop function to hook up and use the bkwthread :eek:
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 :( :( :( :cry: :cry: :cry: :cry:
Thank you
-
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();
???
-
Re: Create threads
Thanks
I'm trying to create n threads. It fails at AllocThread's new
-
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);
}
}