class member function as the start function for pthread_create
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > class member function as the start function for pthread_create




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    class member function as the start function for pthread_create  
googler


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-18-04 12:50 PM

how to make a class member function as the start function for the
pthread_create

my code::

class thread
{
public :
void * run( void *);

void start( )
{
pthread_t tid;
pthread_create ( & tid, NULL, &run, NULL );
}
};

:The compiler complains that it cannot perform a cast from
void * (thread::*) (void * )  to void *(*)(void *)






[ Post a follow-up to this message ]



    Re: class member function as the start function for pthread_create  
joe@invalid.address


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-18-04 12:50 PM

"googler" <arun_ccjl@yahoo.co.in> writes:

> how to make a class member function as the start function for the
> pthread_create

You can ususally get away with making it a static class member
function, but strictly speaking you should just define a free function
that takes a pointer to the object.

Joe
--
We can't all be heroes because someone has to sit on the curb and
clap as they go by.
- Will Rogers





[ Post a follow-up to this message ]



    Re: class member function as the start function for pthread_create  
Darko M.


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-18-04 10:55 PM

"googler" <arun_ccjl@yahoo.co.in> wrote in message news:<cddk7o$fqf@odbk17.prod.google.com>.
.
> how to make a class member function as the start function for the
> pthread_create
>
> my code::
>
> class thread
> {
> public :
> void * run( void *);
>
> void start( )
> {
> pthread_t tid;
> pthread_create ( & tid, NULL, &run, NULL );
> }
> };
>
> :The compiler complains that it cannot perform a cast from
> void * (thread::*) (void * )  to void *(*)(void *)

The problem is that the C++ class methods have a hidden argument,
which is the pointer to the structure in the name of which the
function executes ("this"). This is true in case the function is not
static. You could try making run() be static method, and then try
again.

This problem is pretty often, since pthread library is a C interface,
not C++.

Cheers





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 11:03 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register