This is the mail archive of the pthreads-win32@sources.redhat.com mailing list for the pthreas-win32 project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Using a class method as starting routine.


Greets,

A rather dump question: how to use a class method as a starting routine
of pthread_create().

I have the following code:
/*    create.h    */
#ifndef _CREATE_H_
#define _CREATE_H_

#include <stdio.h>
#include "pthread.h"

class create
{
public:
 create();
 void *thread_routine(void *arg);
 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, NULL);

}

create::create()
{
}

When I compiled it using VC6.0 (win32-pthread library of course), I got

create.cpp
C:\ye\work\vs\pthread_projects\create\create.cpp(14) : error C2664:
'pthread_create' : cannot convert parameter 3 from 'void *(void *)' to
'void *(__cdecl *)(void *)'
        None of the functions with this name in scope match the target
type
Error executing cl.exe.


It seems that the compiler does not recognize thread_routine as a
address. Why does it happen? How to get around of it?

Thanks a lot!

--ye


--
Ye Liu
Tel(O) 650-846-5228



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]