Solved

Problem with compiling ThreadPools, multiple threads.

Posted on 2006-11-17
5
314 Views
Last Modified: 2010-04-24
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[i] = gcnew ManualResetEvent(false);
   dthread^ t = gcnew dthread(this->clb_List->Items[a]->ToString(), MRE[i]);
   WTHREAD[i] = 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 that's right. Can anyone point me into the right direction.

TIA.
0
Comment
Question by:kzsigo
  • 3
  • 2
5 Comments
 
LVL 48

Expert Comment

by:AlexFM
ID: 17970512
Try this:

ThreadPool::QueueUserWorkItem(gcnew System::Threading::WaitCallback(t, &dthread::ThreadCallBack),i);
0
 

Author Comment

by:kzsigo
ID: 17984372
Unfortunately that brings me to a Link error.
Do I need to include a class prototype?

LNK2020 : unresolved token (06000000E) CU.Form1::ThreadCallBack

TIA.
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 17985389
What is the class where ThreadCallBack function is defined? Please post enough information.
0
 

Author Comment

by:kzsigo
ID: 17990027
The class that I'm developing is:

"dthread".

Form1::bn_start_Click is where:

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

is defined.

dthread is in a separate file.
With the function being defined inside the dthread.cpp.
 
The class has a couple functions with the ThreadCallBack being the function that I'd like executed.

Inside another class, Form1, is where I'm creating 5 threads. Each thread is one instantiation of dthread.
I guess, in specific, I have Void Form1::bn_start_Click(Object^ sender, System::EventArgs^ e) which creates the five . This function is actually defined in the Form1.h


Would you like me to post more information about the class itself? Like the code of the class?
0
 
LVL 48

Accepted Solution

by:
AlexFM earned 125 total points
ID: 17993667
LNK2020 : unresolved token (06000000E) CU.Form1::ThreadCallBack

This message is about Form1::ThreadCallBack. Do you have such function is Form1? Such message can be shown when function is only declared but doesn't have implementation.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
DLL Windows equivalent in MAC OS 8 127
VC++ 6.0 issue 3 71
C++ - Loading Managed Assembly From Memory in Unmanaged Process 25 484
Which IDE to use to begin C++ training? 5 63
The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
In Easy String Encryption Using CryptoAPI in C++ (http://www.experts-exchange.com/viewArticle.jsp?aid=1193) I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question