C
Christian Buckl
Hi,
I try to implement my own thread class based on POSIX threads. I want my
class to manage everything (creation of threads, exception handling...).
This includes also some functions that need to be called within the threads
context (like setting the cancelability state and type). That´s why I am
using a function that initializes the thread and then calls the original
thread function.
The problem is, that I can't manage to implement the initializing function
within my class.
The code is added at the end of this message. I currently use an extra
initialising function outside my class. This function initializes the thread
and then calls the origin thread function. This works very well. But if I
try to implement the init function as member of the class I have problems
to convert the function properly to have the right parameter for the
pthread_create call.
I look forward for your answers
Chris
//myThread.h
class MyThread
{
public:
MyThread(int threadPriority, void* (*threadFunction)(void*));
...
void* (*mThreadFunction)(void*); //the original thread function
...
};
void* initThread(void* arg); //the thread initialising function
--------------------------------------------------------------------
//myThread.cc
MyThread::MyThread(int threadPriority, void* (*threadFunction)(void*));
{
...
mThreadFunction=threadFunction; //I save the original thread function
...
pthread_create(&mThreadID,&attr,initThread,(void*) this); //create a
thread that uses the initializing function
}
void* initThread(void* arg)
{
ZerberusThread* tmp;
//initialisation of thread
...
//execute now the original thread function
tmp=(ZerberusThread*) arg;
tmp->mThreadFunction(NULL);
}
I try to implement my own thread class based on POSIX threads. I want my
class to manage everything (creation of threads, exception handling...).
This includes also some functions that need to be called within the threads
context (like setting the cancelability state and type). That´s why I am
using a function that initializes the thread and then calls the original
thread function.
The problem is, that I can't manage to implement the initializing function
within my class.
The code is added at the end of this message. I currently use an extra
initialising function outside my class. This function initializes the thread
and then calls the origin thread function. This works very well. But if I
try to implement the init function as member of the class I have problems
to convert the function properly to have the right parameter for the
pthread_create call.
I look forward for your answers
Chris
//myThread.h
class MyThread
{
public:
MyThread(int threadPriority, void* (*threadFunction)(void*));
...
void* (*mThreadFunction)(void*); //the original thread function
...
};
void* initThread(void* arg); //the thread initialising function
--------------------------------------------------------------------
//myThread.cc
MyThread::MyThread(int threadPriority, void* (*threadFunction)(void*));
{
...
mThreadFunction=threadFunction; //I save the original thread function
...
pthread_create(&mThreadID,&attr,initThread,(void*) this); //create a
thread that uses the initializing function
}
void* initThread(void* arg)
{
ZerberusThread* tmp;
//initialisation of thread
...
//execute now the original thread function
tmp=(ZerberusThread*) arg;
tmp->mThreadFunction(NULL);
}