Monday, November 20, 2006
Thursday, November 16, 2006
Tuesday, October 03, 2006
Using pthread in classes
http://sources.redhat.com/ml/pthreads-win32/2001/msg00075.html
/* create.h */
#ifndef _CREATE_H_
#define _CREATE_H_
#include
#include "pthread.h"
class create
{
public:
create();
static void *thread_routine(void *arg)
{
create *pObject = (create *)pObject;
...
}
void start();
};
#endif
/* create.cpp */
#include "create.h"
void *create::thread_routine(void *arg)
{
printf("The thread is here\n");
return NULL;
}
void create::start()
{
pthread_t thread_id;
pthread_attr_t thread_attr;
pthread_create(&thread_id, &thread_attr, create::thread_routine, (void *)this);
}
Pass this as the arg to the thread routine to enable it to access the
members/methods of the class: static function can only access the static
members/methods of the class. I feel it is an even better way in sense of Object
Oriented.

