Solved

Thread controlling function as non-global

Posted on 1998-10-27
3
423 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 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…

696 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