[Fwd: Re: pthread_create() and class member functions....]

From: Victor Perevoztchikov (perev@bnl.gov)
Date: Thu Sep 30 1999 - 19:23:15 MEST


-------- Original Message --------
Subject: Re: pthread_create() and class member functions....
Date: Thu, 30 Sep 1999 12:45:28 -0400
From: Victor Perevoztchikov <perev@bnl.gov>
Organization: STAR.bnl
To: KOSU_FOKIN@garbo.lucas.lu.se
References: <01JGL8HOWG7M90OQJL@garbo.lucas.lu.se>

Hi Anton,
> You're probably trying to pass a class member function or some other C++ thing as third
> argument to pthread_create(). Recall that pthread_create() is a C function, and it must be
> passed a C function as third argument.
> 
Standard of Posix Thread does not allow to call member function of a class.
Actually, it is limitation not of Posix Thread but C++ itself. To call function
by pointer in C it is enough this pointer but to call member function you need
pointer to class and pointer to function. But if your function is static member
you can do it. 
Or you always can pass via void pointer, pointer to any object which can keep
any information, and can call what ever you want. 

Victor

KOSU_FOKIN@garbo.lucas.lu.se wrote:
> 
> Hello rooters!
> 
> I am trying to play around C++ implementation of posix threads and I realise
> that I can't pass a class member function into pthread_create() which takes an
> address of a function (void*) as the third argument. It says
> 
> "builder.cxx", line 122: Error: Formal argument 3 of type void*(*)(void*)
> in call to pthread_create(unsigned*, const _pthread_attr*, void*(*)(void*), void*)
> is being passed void*(TVME::*)(void*).
> 
> Could someone tell me how to solve the problem?
> 
> It also says on the web in Linux FAQ
> 
> F.2: I'm trying to use LinuxThreads from a C++ program, and the compiler complains about the third argument to pthread_create() !
> You're probably trying to pass a class member function or some other C++ thing as third
> argument to pthread_create(). Recall that pthread_create() is a C function, and it must be
> passed a C function as third argument.
> 
> But that's rather strange ...
> 
> I suppose that ROOT OO thread wrapper does this job. How?
> 
> Best regards,
> Anton

-- 
Victor M. Perevoztchikov   perev@bnl.gov  perev@vxcern.cern.ch       
Brookhaven National Laboratory MS 510A PO Box 5000 Upton NY 11973-5000
tel office : 516-344-7894; fax 516-344-4206; home 516-345-2690



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:43:40 MET