Re: pthread_create() and class member functions....

From: Walter F.J. Mueller (mueller@axp602.gsi.de)
Date: Fri Oct 01 1999 - 20:23:18 MEST


Hello Anton, Joern,

please don't mix a ptr-to-function and a ptr-to-member-function.
The former is just the address of a function. The later is
a structure containing

    the function address for non-virtual functions
    the vtable index for virtual functions
    the this pointer offset

The representation of the structure is implementation specific,
and does for some compilers even depend on whether the class
has virtual functions or multiple inheritance or not.

All this is needed to calculate 
	the actual entry point address
	and the effective this pointer
when the ptr-to-member-function is finally used in a call.
In cases like multiple inherited base classes with virtual
functions in virtual base classes things get nontrivial here!

Inspect the C++ lanuage definition for the allowed conversions
and casts of a ptr-to-member-function, and you'll see, there are
very few.

In the light of all this I wonder portable Joern's code example is.

Beyond that, the code

 TThread* mythread= new TThread("My Thread",
         (void(*) (void *)) &Myclass::myfunction,
         (void*) &Myclass);

will probably not give the desired result if Myclass uses
multiple inheritance and myfunction is from one of the base
classes (that's why the PTMF struct may contain a this offset).


			With best regards,	Walter

--
Walter F.J. Mueller   Mail:  W.F.J.Mueller@gsi.de
GSI,  Abteilung KP3   Phone: +49-6159-71-2766
D-64291 Darmstadt     FAX:   +49-6159-71-2989
WWW:   http://www-kp3.gsi.de/www/kp3/people/mueller.html
PGP:   http://www-kp3.gsi.de/~mueller/pgp.shtml



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