Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Thread controlling function as non-global

Posted on 1998-10-27
3
Medium Priority
?
440 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 200 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

609 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