Solved

Thread controlling function as non-global

Posted on 1998-10-27
3
412 Views
Last Modified: 2013-11-20
I am using Visual c++ 5 to join two previous c++ programs and am using multithreading to let them run simultaneously.

I have built the GUI in a project and would like to add the other program to run as a worker thread when required.

I wan't the worker thread to have access to members of MFC classes in the original GUI thread. The problem I am having is in calling the worker thread from within a member function of the GUI thread.

I am trying to do this with code like this:

AfxBeginThread( (AFX_THREADPROC ) CMatchThread::MatchThreadProc, m_pPose);

where the actual controlling function is defined in the CMatchThread class as follows:

static UINT MatchThreadProc(LPVOID);

The error I get is this:
error C2440: 'type cast' : cannot convert from 'overloaded function type' to 'unsigned int (__cdecl *)(void *)'
                                                     None of the functions with this name in scope match the target type

I can't understand what's wrong with my typecast, I know it's possible to declare the controlling function as a non-global, where am I going wrong?
0
Comment
Question by:gavinpat
3 Comments
 

Expert Comment

by:kahhoe
ID: 1323897
hi gavinpat,

If I remember correctly, thread only work with C functions.  There are issue like stack and heap size to set too.  

One solution is to create a C function thread to run your class functions.  For example,

threadfunc1()
{
  CMatchThread::MatchThreadProc();  
}

Try to look for ACE (Adaptive Communication Envirnoment, I think) for information on how to implement multi-thread class.  Or just buy thread.h++ from roguewave.



Best Regards,
Kah Hoe
0
 
LVL 1

Accepted Solution

by:
Bridge earned 100 total points
ID: 1323898
Pass the class object as the parameter to the thread function.
0
 

Author Comment

by:gavinpat
ID: 1323899
Bridge, surely passing the class object as the parameter would mean that the thread becomes a GUI thread instead of a worker thread? I don't really want the overhead of a message pump slowing down the rest of the program.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
sumDigits challenge 9 120
notReplace  challenge 53 115
wait notify demo infinite loop 3 95
Excel file not created as expected 7 46
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…

930 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now