ThreadPool Error Compiling, Pointer To Member.

G

gnassar

This question is prob. extremely trivial but I can't seem to find out
what is going on. I've been doing some basic work with Multithreading
and Worker Threads and have determined I'd like to set up a minor
project that has ThreadingPools.

I can't seem to get it to compile whether I follow the example
tutorials or I don't. Of course the latter has a higher percentage of
failing :)

Anyways the line that fails is:
ThreadPool::QueueUserWorkItem(gcnew
System::Threading::WaitCallback(t->ThreadCallBack),i);

The examples don't show anything being passed into the function but
it's a bit necessary for me to have each of the threads know what
numbers they are. So I'd really like to send in the number they are.

The function I'm sending them to is:
void dthread::ThreadCallBack(Object^ threadContext){
...
....
...
}


Now the errors I get all have to do with delegation of functions or
with pointers. I assumed that with this being a managed project I
didn't have to deal with most of that.

Errors:
Error 1 error C3867: 'dthread::ThreadCallBack': function call missing
argument list; use '&dthread::ThreadCallBack' to create a pointer to
member

Error 2 error C3350: 'System::Threading::WaitCallback' : a delegate
constructor expects 2 argument(s)

Before you go about telling me that I shouldn't be using -> to point to
the function in the class allow me to tell you that my function is
*not* static. Furthermore I have instantiated the class before hand.
I"ve been following two tutorials from msdn, one does it, the other
doesn't.

Ie:

for (int i = 0; i........; i++){
MRE = gcnew ManualResetEvent(false);
dthread^ t = gcnew dthread(this->clb_List->Items[a]->ToString(),
MRE);
WTHREAD = t;
System::UInt32^ m_i = gcnew UInt32(i);
ThreadPool::QueueUserWorkItem(gcnew
System::Threading::WaitCallback(t->ThreadCallBack),i);
}

Now I can make one of them go away by removing the parameter or even
moving the parameter into the WaitCallback but I dont think thats
right. Can anyone point me into the right direction.

TIA.
G
 
B

Ben Voigt

This question is prob. extremely trivial but I can't seem to find out
what is going on. I've been doing some basic work with Multithreading
and Worker Threads and have determined I'd like to set up a minor
project that has ThreadingPools.

I can't seem to get it to compile whether I follow the example
tutorials or I don't. Of course the latter has a higher percentage of
failing :)

Anyways the line that fails is:
ThreadPool::QueueUserWorkItem(gcnew
System::Threading::WaitCallback(t->ThreadCallBack),i);

That's how C# would do it...

In C++/CLI you need
ThreadPool::QueueUserWorkItem(gcnew System::Threading::WaitCallback(t,
&dthread::ThreadCallBack),i);

The examples don't show anything being passed into the function but
it's a bit necessary for me to have each of the threads know what
numbers they are. So I'd really like to send in the number they are.

The function I'm sending them to is:
void dthread::ThreadCallBack(Object^ threadContext){
..
...
..
}


Now the errors I get all have to do with delegation of functions or
with pointers. I assumed that with this being a managed project I
didn't have to deal with most of that.

Errors:
Error 1 error C3867: 'dthread::ThreadCallBack': function call missing
argument list; use '&dthread::ThreadCallBack' to create a pointer to
member

Error 2 error C3350: 'System::Threading::WaitCallback' : a delegate
constructor expects 2 argument(s)

Before you go about telling me that I shouldn't be using -> to point to
the function in the class allow me to tell you that my function is
*not* static. Furthermore I have instantiated the class before hand.

Doesn't matter. You can only refer to a member function by the class name,
not by an instance.
I"ve been following two tutorials from msdn, one does it, the other
doesn't.

Ie:

for (int i = 0; i........; i++){
MRE = gcnew ManualResetEvent(false);
dthread^ t = gcnew dthread(this->clb_List->Items[a]->ToString(),
MRE);
WTHREAD = t;
System::UInt32^ m_i = gcnew UInt32(i);
ThreadPool::QueueUserWorkItem(gcnew
System::Threading::WaitCallback(t->ThreadCallBack),i);
}

Now I can make one of them go away by removing the parameter or even
moving the parameter into the WaitCallback but I dont think thats
right. Can anyone point me into the right direction.

TIA.
G
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top