TThread with classes

Hi forum,

Im trying to launch a member function as a thread, as described in section 6.1 @
www-linux.gsi.de/~go4/HOWTOthrea … frame.html
but is currently having some problem accessing class variables and functions from within the thread.

This is what I do: I define my member function static, and provide the “this”-pointer as argument so I have access to my class variables and functions from within the thread. You can see the relevant part of code of the .hpp and .cpp files below. However, when compiling I get an error message (shown below) at the line where my thread try to access a getter member function. Why is that? How can I solve it?

MyClass.cpp: In static member function ‘static void* MyClass::MyThread(void*)’:
MyClass.cpp:94: error: ‘void*’ is not a pointer-to-object type

many thanks
Phermi

MyClass.cpp: In static member function ‘static void* MyClass::MyThread(void*)’:
MyClass.cpp:94: error: ‘void*’ is not a pointer-to-object type

MyClass.hpp

void static *MyThread(void *ptr);

MyClass.cpp

int MyClass::RunThread(void){

mythread = new TThread(“MyThread”, (void() (void ))MyThread, (void)this);
mythread->Run();
return 1
}
void
MyClass::MyThread(void *ptr)
{
cout << "Number " << ptr->ReturnNumber() << endl;
}

Im using:
gcc (Ubuntu 4.3.3-5ubuntu4) 4.3.3
root 5.24/00

Hi Phermi,

You should start by taking a look at $ROOTSYS/test/threads.cxx, and at the tutorials in $ROOTSYS/tutorials/thread/ (as the GSI page is a bit outdated - 2001 - and not under our control…)
You may also take a look at some of the older post on this forum, e.g.
root.cern.ch/phpBB2/viewtopic.php?t=7162
root.cern.ch/phpBB2/viewtopic.php?t=9594

Cheers, Bertrand.