[lug] pthreads, reprise

Sebastian Sobolewski spsobole at mindless.com
Wed May 31 20:41:40 MDT 2000


Not to my knowledge. But there is a way around it.  Create the function 
that you will pass into create thread ( this will be your relay function 
).  For the optional parameter to create_thread pass in the pointer to your 
class that contains the class function you wish to call inside the 
thread.  Then inside your relay function that you passed into 
create..thread reverse cast the parameter to your class object and call the 
memeber function.

         Example:

void pthread_fork()
{
         TYourClass *yourClass = new TYourClass();  // class containing the 
meber func


         // create a new thread with that will execute realyFunc
         // the optional parameter is a pointer to the TYourClass object

         pthread_create(&irq_thread,NULL,(void *)&relayFunc,yourClass);
}


void relayFunc(void *ptr)
{
         TYourClass *yourClass;

         // If the thread parameter is valid
         if(ptr)
         {
                 // reverse cast it as a TYourClass object
                 yourClass = (TYourClass *) ptr;

                 // Call it's member
                 yourClass->MemberFunc();
         }

         pthread_exit(0);
}


Let me know if this works for you.
Sebastian


At 04:43 PM 5/31/00 -0600, you wrote:
>Once again, my thanks to those who helped with the linker option for
>multithreaded C++ code.  Perhaps you would be willing to assist with another
>question?
>
>Is it possible to invoke pthread_create(..) and pass the name of a class
>method?  I am having no problems passing the names of routines that are
>outside the class, but am unable to pass a class method name.  I am
>suspecting it has something to do with name decoration, but I have no idea
>how to make it work.
>
>--Kevin
>kevin at precisonline.com
>http://www.precisonline.com
>http://www.precisonline.com/gold.htm
>
>
>
>_______________________________________________
>Web Page:  http://lug.boulder.co.us
>Mailing List: http://lists.lug.boulder.co.us/mailman/listinfo/lug

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lug.boulder.co.us/pipermail/lug/attachments/20000531/c65d9ff5/attachment.html>


More information about the LUG mailing list