pthreads confusion

"Jon Earle" <[email protected]>
Newsgroups gmane.user-groups.linux.ottawa.general
Message-ID <[email protected]>
I'm trying to create a thread (actually more than one, but just start with
one for now) that runs a method in another object.  I should this this would
be relatively straightforward.  I've worked up a code example to illustrate
the problem (though I get two different reactions [both noted in the code
snippet below] from the compiler [same call to pthread_create] when I compile
this vs my real program).

Here's hoping there's a simple explanation and resolution.

Compiled using: g++ -o tst main.cpp

Contents of main.cpp:

#include <pthread.h>
#include <iostream>

using namespace std;

class MyClass
{
public:
    void* Run(void* parm)
    {
        char *p = (char *)parm;
        cout << p;
    }
};

class MyControlClass
{
public:
    MyClass*    object;
    pthread_t   tid;
};

void MakeThread(MyControlClass* myCC)
{
    myCC->object = new MyClass;

    // This line throws:
    //  error: argument of type ‘void* (MyClass::)(void*)’ does not match
‘void* (*)(void*)’))))
    pthread_create(&(myCC->tid), NULL, myCC->object->Run, (void*)myCC);

    // Another prog throws (same call as above):
    // error: ‘void*’ is not a pointer-to-object type
    //
    // In that case, the class defs are in separate code files and
MyControlClass is a template
    // class.
}

int main ()
{
    MyControlClass ctlClass;
    MakeThread(&ctlClass);
    return 0;
}


-- 
OCLUG general discussion list
[email protected]
http://oclug.on.ca/mailman/listinfo/oclug
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.